It's actually much simpler:
 
---
var fs = require('fs')
var sql_file = function(sql_file, callback) {
    fs.readFile("./SQLs/" + sql_file, "utf8", function(err, data) {
        if (err) throw err
        callback(data)
    })
}
...
 
And call it like this:
---
require('your-module').sql_file(function(data) {
    console.log(data)
})
...
 
Answering to your next question: no, there is no way to make asynchronous function to return something synchronously, but you can use generators to mitigate this issue (but it's better to learn how node.js works first).
 
// alex
 
 
 
07.03.2014, 05:43, "Bob Spero" <[email protected]>:
I am using the below to read a select statement that I am trying to pass to another function, how can I get select_statement to return into a string so I can use it just like sql_file in the below? I am new to js and I am not sure I understand the structure yet but I am really stuck here!

fs = require('fs');
var sql_file = function(sql_file) {
    var select_statement
    fs.readFile("./SQLs/" + sql_file, "utf8", function(err, select_statement) {
        //console.log(select_statement);
        return select_statement;
    });
    return sql_file;
    console.log(select_statement);
    return select_statement;
    return test;
};
 
 
module.exports.sql_file = sql_file;

 

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to