My task is a very simple one, send an http/https request to a server, get back the HTML,JSON or XML and process the data.
I understand that there are 2 modules that can do the module part. nodejs.org/api/http.html and https://www.npmjs.com/package/request
I guess request is more advanced. Other than that is there any difference between the 2 which makes one more suitable or less suitable for the task I said?
Node. js has a built-in module called HTTP, which allows Node. js to transfer data over the Hyper Text Transfer Protocol (HTTP). To include the HTTP module, use the require() method: var http = require('http');
http module The HTTP options specify the headers, destination address, and request method type. Next, we use http. request to send the data to the server and await the response. The response is stored in the req variable, and upon error, it is logged into the console.
HTTP is an independent module. Express is made on top of the HTTP module. HTTP module provides various tools (functions) to do things for networking like making a server, client, etc. Express along with what HTTP does provide many more functions in order to make development easy.
The http
package contains support for the raw HTTP protocol. While it can do everything, often it's a bit clumsy to use.
The request
module uses the http
module and adds a lot of sugar to make it easier to digest: A lot of common cases can be handled with just a tiny bit of code, it supports piping request data, forwarding requests to a different server, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With