Skip to content

Instantly share code, notes, and snippets.

@ozten
Created August 6, 2013 20:38
Show Gist options
  • Save ozten/6168399 to your computer and use it in GitHub Desktop.
Save ozten/6168399 to your computer and use it in GitHub Desktop.
Playing with promises
var p = require("p-promise");
var promise = p.defer();
promise.then(function() {
fs.readFile("sample.json", 'utf8');
})
.then(function(data) {
var o = JSON.parse(data);
o.foo = "bar";
fs.writeFile("sample.json", JSON.stringify(o), {encoding: 'utf8'});
})
.then(function() {
console.log("Finished");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment