ItSolutionStuff.com

Node JS Make Http Get Request with Parameters Example

By Hardik Savani May 1, 2021
Node JS

Hi,

This article will give you example of node js make http get request with parameters. you can understand a concept of node js https request query parameters. you will learn how to make an http get request in node.js. you will learn make http get request nodejs. Let's get started with node js axios http get request example.

i will give you two examples, using axios and request npm package for male get http request with parameters using node js. let's see both example with output as bellow:

Example 1: HTTP GET Request using Axios

Create Node App:

mkdir my-request-app

cd my-request-app

npm init

Install Axios:

npm install axios --save

server.js

const axios = require('axios');

const querystring = require('querystring');

const data = {

page: 2,

};

const parameters = querystring.stringify(data);

axios.get('https://reqres.in/api/users?'+parameters)

.then((res) => {

console.log(`Status: ${res.status}`);

console.log('Body: ', res.data);

}).catch((err) => {

console.error(err);

});

Run App

node server.js

Output

Example 2: HTTP GET Request using Request

Create Node App:

mkdir my-request-app

cd my-request-app

npm init

Install Axios:

npm install request --save

server.js

const request = require('request');

const querystring = require('querystring');

const parameters = {

page: 2,

};

const get_request_args = querystring.stringify(parameters);

const options = {

url: 'https://reqres.in/api/users?'+get_request_args,

json: true

};

request.get(options, (err, res, body) => {

if (err) {

return console.log(err);

}

console.log(`Status: ${res.statusCode}`);

console.log(body);

});

Run App

node server.js

Output

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to run node js server on https using self-signed certificate?

Read Now →

Node JS Express Form Submission Example

Read Now →

Node JS Mysql Connection Example

Read Now →

Node JS Multer Rename Uploaded File Example

Read Now →

React Axios Delete Request Example

Read Now →

React Axios Post Request Example

Read Now →

React Axios Get Request Example

Read Now →

Laravel React JS Axios Post Request Example Tutorial

Read Now →

How to Download File using Axios Vue JS?

Read Now →

Vue Axios Post Request Example Tutorial

Read Now →

File Upload using Vue js Axios PHP Example

Read Now →

Laravel Vue JS Axios Post Request Example

Read Now →