EN
Node.js - HTTP POST request using axios
0 points
In this article, we would like to show you how to make HTTP POST request using axios in Node.js.
Quick solution:
xxxxxxxxxx
1
const axios = require('axios');
2
3
axios({
4
method: 'post',
5
url: '/register',
6
data: {
7
username: 'user1',
8
password: 'password1',
9
},
10
}).then((response) => {
11
console.log(response);
12
});
1. Install axios
xxxxxxxxxx
1
npm install axios
2. Import axios
using require()
xxxxxxxxxx
1
const axios = require('axios');
3. Make POST request using axios
.
In below example we register user using axios
POST request.
Example:
xxxxxxxxxx
1
const axios = require('axios');
2
3
axios
4
.post('/register', {
5
username: 'user1',
6
password: 'password1',
7
})
8
.then((response) => {
9
console.log(response);
10
})
11
.catch((error) => {
12
console.log(error);
13
});