Make a GET request to JSON API in Node.js?

后端 未结 3 1327
一个人的身影
一个人的身影 2021-02-04 14:42

Wondering how I can make a GET request to a JSON API using Node.js. I preferably want to use Express however it is not necessary, and for the output to be on a Jade page. I\'m s

3条回答
  •  失恋的感觉
    2021-02-04 14:56

    I like to use the request package:

    npm install --save request
    

    And the code:

    var request = require('request');
    
    request({url: 'http://yourapi.com/', json: true}, function(err, res, json) {
      if (err) {
        throw err;
      }
      console.log(json);
    });
    

提交回复
热议问题