How to send a mail request using the request library and Bluebird?

So my installation:

var Promise = require("bluebird"); var request = Promise.promisify(require('request')); 

It works:

 request('url') 

He returns a promise

It does not mean:

 request.post('url', {form: {type: 'artist'}}) 

gives me this error:

 TypeError: Object function promisified(_arg0,_arg1) { ... }has no method 'post' at /Users/beamer30/projects/wevo/controllers/music.js:85:30 at Array.map (native) at MusicSearch.spotifyRelated (/Users/beamer30/projects/wevo/controllers/music.js:84:22) at MusicSearch.findRelatedArtists (/Users/beamer30/projects/wevo/controllers/music.js:48:7) at musicController.search (/Users/beamer30/projects/wevo/controllers/music.js:100:17) at Layer.handle [as handle_request] (/Users/beamer30/projects/wevo/node_modules/express/lib/router/layer.js:76:5) at next (/Users/beamer30/projects/wevo/node_modules/express/lib/router/route.js:100:13) at Route.dispatch (/Users/beamer30/projects/wevo/node_modules/express/lib/router/route.js:81:3) at Layer.handle [as handle_request] (/Users/beamer30/projects/wevo/node_modules/express/lib/router/layer.js:76:5) at /Users/beamer30/projects/wevo/node_modules/express/lib/router/index.js:227:24 

any ideas on how to make this work? What is the right way to do this?

+5
source share
1 answer

When you promise to return a request, you promise only the returned function. Instead, use promisifyAll , which promises a holistic object. Since request is that you did not receive an error.

 var Promise = require("bluebird"); var request = Promise.promisifyAll(require('request')); // this will work 
+8
source

Source: https://habr.com/ru/post/1200357/


All Articles