This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name":"The 40-Year-Old Virgin" | |
}, | |
{ | |
"name":"51 Birch Street" | |
}, | |
{ | |
"name":"The Adventures of Sharkboy and Lavagirl in 3-D" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var fileContent = fs.readFileSync('sync.js','utf8'); | |
console.log(fileContent); | |
console.log("something else"); | |
//Output | |
//Same code content | |
//something else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
fs.readFile('async.js','utf8',function(err,data){ | |
if(!err) { | |
console.log(data); | |
} | |
}); | |
console.log("something else"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var db = require('somedbfile.js'); | |
var sendEmail = require('someEmail.js'); | |
fs.readFile('async.js','utf8',function(err,data){ | |
if(!err) { | |
console.log(data); | |
} | |
db.executeQuery('SELECT * FROM test',function(err,rows) { | |
if(!err) { | |
console.log("Error",err); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
fs.readFile('async.js','utf8',function(err,data){ | |
if(!err) { | |
console.log(data); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
fs.readFile('async.js','utf8',fileContent); | |
function fileContent(err,data) { | |
if(!err) { | |
console.log(data); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var fs = require('fs'); | |
var co = require('co'); | |
co(function* () { | |
var file1 = yield readFile('demo.js'); | |
console.log(file1); | |
console.log("I am after file read even though its Async"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'); | |
// Converts all function of 'fs' into promises. | |
var fs = Promise.promisifyAll(require('fs')); | |
fs.readFileAsync('file.js','utf8') | |
// 'then' when result comes. | |
.then(function(data) { | |
console.log(data); | |
}) | |
//'catch' when error comes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EventEmitter = require('events').EventEmitter; | |
var emitter = new EventEmitter(); | |
var fs = require('fs'); | |
// Event to read file - generic function. | |
emitter.on('start_read',function(file_name) { | |
console.log("Started Reading file....\n\n"); | |
fs.readFile(file_name, 'utf8', function (err,data) { | |
if (err) { | |
console.log("Error happens."); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
async.parallel([ | |
function(callback) { | |
// Some Async task | |
callback(); | |
}, | |
function(callback) { | |
// Some Async task | |
callback(); |
OlderNewer