Can I use readFile to set properties for my App ?

NodeBB Development
  • I do not know if I am asking the right question in the right group or what, but I can use some help here. I am trying to build a node.js application having the node oracle module. I want to read the raw sql files on my server side and use them in my connection.execute(select.toString(), [], function(err, results) function. So to test it I create a var and did select * from inventory and it works as anticipated. So now I figure why retype just read my sql files and if I want to make changes I just change the sql file. Below is my code, how the heck do I get these in my select var. I have been told to use readFileSync but I read you should not use that on the server side. And yes I am new, just about four days with node.


    var fs = require('fs');
    function sql_file(sql_file, cb) {
        console.log('about to read file');
        var fileName = "./SQLs/" + sql_file;
        fs.readFile(fileName, function(err, buffer) {
            console.log('the file has been read');
            if (err) return cb(err);
            return cb(null, buffer.toString());
        console.log('call to read file made (but not finished)');
    sql_file('inventory.sql', function(err, contents) {
    module.exports.sql_file = sql_file;
  • Hey @bobspero! Welcome to NodeBB! We're not a Node.js discussion forum, but hell, why not? Ask anyway, maybe we can help.

    1. What happens if you try fs.readFile(filename, { encoding: 'utf-8' }, function(err, data) { .. })? No need to use .toString() then.
    2. What happens if you try fs.readFileSync instead?
    3. At the file has been read, what does buffer.toString(); contain?
  • I got it, thanks!

Suggested Topics