express make request to api 1

express make request to api

// Requirements: npm install request

const request = require('request');
request('', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log( body ); 

Here is what the above code is Doing:
1. We’re requiring the request module.
2. We’re making a request to the URL
3. We’re passing a callback function to the request method.
4. The callback function has three parameters: error, response, and body.
5. If there is no error and the response code is 200, we print the body.

Similar Posts