Node Js Request Package

Posted on  by admin

TLS/SSL Protocol

There are multiple ways to make HTTP requests in Node.js. We can do so using the standard HTTP/HTTPS module, of course, or we could use one of a number of npm packages that make our lives much easier.

In this post, we are going to see code examples of the native HTTPS module that comes built-in with your Node.js installation as well as npm packages like Axios, Got, SuperAgent, and node-fetch.

Let’s get cracking! Before we dive into the description and code, below are some prerequisites you’ll need to get your hands dirty with some Node.js code, which involves calling a remote mock JSON API:.

You should have Node.js running on your machine (maybe as a Docker container). All the examples will be run using Node.js 14.x, the active LTS.

request(options, callback)

You are familiar with npm commands like npm init, and you are able to install npm packages with npm install --save to a project.

You can run the JavaScript files with node on your command line to see example output.

Convenience methods

You are familiar with callbacks, promises, and async/await. Basic things, but good to get them checked before proceeding any further 🙂.