Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblanche/8710894 to your computer and use it in GitHub Desktop.
Save jblanche/8710894 to your computer and use it in GitHub Desktop.
Version 1 :
function readContent(callback) {
fs.readFile("./tmp/tmp.log", function (err, content) {
if (err) return callback(err);
callback(null, content);
})
}
var fileContent = readContent(function (err, content) {
console.log(content);
return content;
})
exports.index = function(req, res){
res.render('index', {
title: 'Express',
content: fileContent
});
};
Version 2 :
function readContent(callback) {
fs.readFile("./tmp/tmp.log", function (err, content) {
if (err) return callback(err);
callback(null, content);
})
}
var fileContent = readContent(function (err, content) {
exports.index = function(req, res){
res.render('index', {
title: 'Express',
content: fileContent
});
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment