Jamsheed Kamarudeen
Jamsheed Kamarudeen

Reputation: 728

What is the difference between request and http modules in node.js?

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?

Upvotes: 35

Views: 14968

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328760

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.

Upvotes: 53

Related Questions