-
-
Save schmaluk/f71f95d557a4b72a9ccfda9a212fd3f7 to your computer and use it in GitHub Desktop.
Promises - Bluebird - Node
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
var AWS = require('aws-sdk'); | |
var S3 = Promise.promisifyAll(new AWS.S3()); | |
return S3.putObjectAsync(params); |
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
var fs = Promise.promisifyAll(require("fs")); | |
fs.readFileAsync("myfile.json").then(JSON.parse).then(function (json) { | |
console.log("Successful json") | |
}).catch(SyntaxError, function (e) { | |
console.error("file contains invalid json"); | |
}).error(function (e) { | |
console.error("unable to read file, because: ", e.message); | |
}); |
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
var Promise = require('bluebird'); | |
var Xray = require('x-ray'); | |
var x = Xray(); | |
var getTitle = Promise.promisify(x('http://google.com', 'title')); | |
getTitle().then(function(title) { | |
console.log(title); // Google | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment