question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Where is Promise in request-promise?

See original GitHub issue

I can’t understand where is a promise in a request-promise. How do I get a promise object, not a Request object?

let rp = require('request-promise');

let p = rp('https://example.com/');

console.log('p', p);

// p is not a promise, it is Request!
Request {
  domain: null,
   ...
     _sessionCache: { map: {}, list: [] } } }

How do I get a promise object? I need it to create an array of promises. But instead I get an array of Requests.

    Object.keys(array).map(id => {
        return rp('https://example.com/' + id); // I expect this to be a Promise, not a Request
    });

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
analog-nicocommented, Nov 14, 2016

Hi @wzup , it is actually both!

What you get is the original request object plus .then(...), .catch(...), and .finally(...) attached. If you want to use request(...).spread(...) for example then do this: request(...).promise().spread(...) But if you just need standard promise capabilities like in your use case with map you can work with rp('https://example.com/' + id) directly since the returned object has a .then(...) method.

Further details see here.

Anything else I can answer for you?

1reaction
analog-nicocommented, Dec 17, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

request-promise - npm
The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.. Latest version: 4.2.6, last published: 2 years ago.
Read more >
Node.js promise request return - Stack Overflow
A promise is an object that serves as a placeholder for a future value. Your parse() function returns that promise object.
Read more >
request-promise JavaScript and Node.js code examples
Most used request-promise functions · RequestPromise.then · RequestPromise.catch · RequestPromise.pipe · RequestPromise.bind · RequestPromise.finally.
Read more >
How to Make API Requests with Request-Promise in Node.js
... of this tutorial for links to prerequisites and related tutorials: https://heynode.com/tutorial/how-make-api-requests- request - promise...
Read more >
How to get node.js HTTP request promise without a single ...
const getContent = function(url) { // return new pending promise return new Promise((resolve, reject) => { // select http or https module, depending...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found