Skip to content

Instantly share code, notes, and snippets.

@schmaluk
Forked from zsim0n/aws-promisify.js
Created April 21, 2018 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmaluk/f71f95d557a4b72a9ccfda9a212fd3f7 to your computer and use it in GitHub Desktop.
Save schmaluk/f71f95d557a4b72a9ccfda9a212fd3f7 to your computer and use it in GitHub Desktop.
Promises - Bluebird - Node
var AWS = require('aws-sdk');
var S3 = Promise.promisifyAll(new AWS.S3());
return S3.putObjectAsync(params);
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);
});
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