Created
April 29, 2012 09:22
-
-
Save klovadis/2548942 to your computer and use it in GitHub Desktop.
Typical node.js callback pattern
This file contains hidden or 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
// include the filesystem module | |
var fs = require('fs'); | |
// fs.readFile: read a file and all its contents, | |
// then call a callback function | |
fs.readFile('/some/file', function (err, contents) { | |
// if any error occurred, throw it | |
if (err) throw err; | |
// do something when no error occurred | |
/* something(); */ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment