Skip to content

Instantly share code, notes, and snippets.

@seanstrom
Last active August 29, 2015 14:13
Show Gist options
  • Save seanstrom/73478f222438d953e3f6 to your computer and use it in GitHub Desktop.
Save seanstrom/73478f222438d953e3f6 to your computer and use it in GitHub Desktop.
Async JS/Node - Node CPS Try-Catch example - Part 1
// Part 1
var fs = require('fs')
, path = 'my_file.txt'
function getFile(path, callback) {
try {
fs.readFile(path, function(err, data) {
if(err) throw err
var wrapperMessage = {coolStuff: true, data: data}
callback(null, wrapperMessage)
})
} catch(error) {
callback(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment