cURL equivalent in Node.js?

后端 未结 18 596
误落风尘
误落风尘 2020-11-29 16:43

I\'m looking to use information from an HTTP request using Node.js (i.e. call a remote web service and echo the response to the client).

In PHP I would have used cUR

18条回答
  •  春和景丽
    2020-11-29 16:58

    There is npm module to make a curl like request, npm curlrequest.

    Step 1: $npm i -S curlrequest

    Step 2: In your node file

    let curl = require('curlrequest')
    let options = {} // url, method, data, timeout,data, etc can be passed as options 
    curl.request(options,(err,response)=>{
    // err is the error returned  from the api
    // response contains the data returned from the api
    })
    

    For further reading and understanding, npm curlrequest

提交回复
热议问题