Node.JS将文件读入字符串以获取外部函数

时间:2014-03-07 00:11:16

标签: javascript node.js

我知道问题是这是如何嵌套但我无法弄清楚如何纠正它。这是一个获取文件名参数的函数。假设抓取select语句并运行查询。所以代替var reader = connection.reader(“SELECT * FROM Inventory”,[]);它看起来像var reader = connection.reader(function(inventory.sql),[]);.但我看不出如何纠正这个!

var fs = require("fs");
var select_statement = "ss";
var sql_file = function(value) {
    var fileName = "./SQLs/inventory.sql";
    fs.exists(fileName, function(exists) {
        if (exists) {
            fs.stat(fileName, function(error, stats) {
                fs.open(fileName, "r", function(error, fd) {
                    var buffer = new Buffer(stats.size);
                    fs.read(fd, buffer, 0, buffer.length, null, function(error, bytesRead, buffer) {
                        var data = buffer.toString("utf8", 0, buffer.length);
                        console.log(data);
                        fs.close(fd);
                    });
                });
            });
        }
    });
};
module.exports.select_statement = select_statement;
module.exports.sql_file = sql_file;
    module.exports.sql_statement = sql_statement;

0 个答案:

没有答案