How HTTP POST requests work in Node ?
Last Updated :
12 Apr, 2025
The HTTP POST method is used to send data from the client to the server. Unlike GET, which appends data in the URL, POST sends data in the request body, which makes it ideal for form submissions, file uploads, and secure data transfers.
In Node.js, handling POST requests is commonly done using the Express.js framework, which simplifies routing and request handling.
HTTP Post in Node
In Node.js, the POST method is typically implemented using the Express framework. Express creates an app server and provides the app.post
method to handle POST.
Syntax:
app.post(route, function(req, res){
//this is a callback function
})
- req (request): contains the data sent by the client
- res (response): used to send data back to the client
To make the http request we uses the we can use axios, node-fetch, and http module. Check this article to know how to make http requests in Node.
Steps to Create the Application
Step 1: Initialising the Node App using the below command:
npm init -y
Step 2: Installing the required packages:
npm i express body-parser
Project Structure:

The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^5.1.0",
}
Example: Below is the basic example of the HTTP POST request using nodejs:
- User accesses the server at
http://localhost:3000/
. - The server sends the HTML form for the user to input two numbers.
- User enters numbers and submits the form.
- The server receives the POST request, extracts the numbers, performs addition, and sends the result as a response.
HTML
// index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Calculator</title>
</head>
<body>
<h1>Simple Calculator</h1>
<form action="/" method="post">
<input type="text" name="num1" placeholder="First Number" required>
<input type="text" name="num2" placeholder="Second Number" required>
<button type="submit">Calculate</button>
</form>
</body>
</html>
</html>
JavaScript
const express = require('express');
const app = express();
const port = 3000;
// Use built-in middleware to parse URL-encoded data (form submissions)
app.use(express.urlencoded({ extended: true }));
// Route to serve the HTML form
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
// Handle POST request
app.post('/', (req, res) => {
const num1 = parseFloat(req.body.num1);
const num2 = parseFloat(req.body.num2);
const result = num1 + num2;
res.send(`The result is: ${result}`);
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
Output:
OutputConclusion
The https post request is created using the express app.post method in backend. This methods sets a callback for the defined route to process the request received from the client side.
Similar Reads
How to make HTTP requests in Node ? In the world of REST API, making HTTP requests is the core functionality of modern technology. Many developers learn it when they land in a new environment. Various open-source libraries including NodeJS built-in HTTP and HTTPS modules can be used to make network requests from NodeJS.There are many
4 min read
How to Send an HTTP POST Request in JS? We are going to send an API HTTP POST request in JavaScript using fetch API. The FetchAPI is a built-in method that takes in one compulsory parameter: the endpoint (API URL). While the other parameters may not be necessary when making a GET request, they are very useful for the POST HTTP request. Th
2 min read
Structure of HTTP request in Postman Postman is a powerful tool that simplifies the process of making HTTP requests for testing APIs. Understanding the structure of a typical HTTP request in Postman is fundamental for everyone who want to test endpoints. In this article, we'll break down the key components of an HTTP request in Postman
3 min read
HTTP Request vs HapiJS Request in Node.js Node.js: Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and itâs not a programming language. Most of the people are confused and understand itâs a framework or a programming languag
3 min read
How Are Parameters Sent In An HTTP POST Request? HTTP POST requests are widely used in web development to send data from a client to a server. Whether you're submitting a form, uploading a file, or sending JSON data via an API, understanding how parameters are sent in an HTTP POST request is important. In this article, weâll explore how are parame
4 min read
Postman - Working, HTTP Request & Responses API...Application Programming Interface... If you're a developer then this word is nothing new for you...Being a developer, you know the importance of API in any kind of application. In simple terms, API is a defined set of rules with some defined methods of communication. With the help of API, soft
5 min read