Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Javascript: How to get 'body' out of request in node.js

I am totally new to Javascript (so please bear with me). I am trying to get the information of an API using request. **I am not using ajax and I am using request. Am I able to do what I want without promises and ajax?

my code is:

  portfolio_value() {
    // retrieve crypto prices from crypto_compare
    const request = require('request');
    
    request('https://min-api.cryptocompare.com/data/pricemulti?fsyms=USD&tsyms=BTC,ETH,XRP&api_key=6e70137ad5b825603d8074b8d5bb8899570052734bc09c2a1b72c118454b6fcb', { json: true }, (err, res, body) => {
      if (err) { 
        return console.log(err); 
      } else {
        console.log(body);   // this works
      };

    console.log(body); // this does not work
      
    });

I am able to print the body using console.log WITHIN request, but how do I get the body OUT of request so that I can return it as an object OUT of portfolio_value()?

Thanks so much.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!