ItSolutionStuff.com

Axios HTTP requests in Node JS Example

By Hardik Savani • May 6, 2021
Node JS

Hi,

Here, i will show you how to works node js axios https request example. step by step explain how to make axios post request in node js. Here you will learn http request in nodejs js axios. i would like to show you axios post request example node js. follow bellow step for axios node js post example.

here, i will give you post, get, put and delete request using axios in node js example. so you can easily use axios https request in node js.

let's see examples bellow:

Create Node App:

mkdir my-request-app

cd my-request-app

npm init

Install Axios:

npm install axios --save

HTTP Post Request:

server.js

const axios = require('axios');

const data = {

first_name: 'Hardik',

last_name: 'Savani',

email: 'hardik@gmail.com'

};

axios.post('https://api.mywebtuts.com/api/users', data)

.then((res) => {

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

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

}).catch((err) => {

console.error(err);

});

HTTP Get Request:

server.js

const axios = require('axios');

const querystring = require('querystring');

const data = {

page: 2,

};

const parameters = querystring.stringify(data);

axios.get('https://api.mywebtuts.com/api/users?'+parameters)

.then((res) => {

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

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

}).catch((err) => {

console.error(err);

});

HTTP Put Request:

server.js

const axios = require('axios');

const data = {

first_name: 'Hardik',

last_name: 'Savani',

email: 'hardik@gmail.com'

};

axios.put('https://api.mywebtuts.com/users/2', data)

.then((res) => {

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

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

}).catch((err) => {

console.error(err);

});

HTTP Delete Request:

server.js

const axios = require('axios');

axios.delete('https://api.mywebtuts.com/api/users/2')

.then((res) => {

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

}).catch((err) => {

console.error(err);

});

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

Node JS Make Http Get Request with Parameters Example

Read Now →

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

Read Now →

Node JS Mysql Connection Example

Read Now →

Node JS Resize Image Before Upload using Multer Sharp

Read Now →

React Axios Post 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 →

Laravel Authenticate User in NodeJS with Socket io using JWT

Read Now →