Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Structure of HTTP request in Postman
Next article icon

How HTTP POST requests work in Node ?

Last Updated : 12 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

NodeProj

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:

httppostGIF

Output

Conclusion

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.




Next Article
Structure of HTTP request in Postman
author
rahulrajendrashewale
Improve
Article Tags :
  • Node.js
  • Web Technologies
  • Node.js-Misc

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
    5 min read
  • How to create a new request in Postman?
    Postman is a development tool that is used for testing web APIs i.e. Application Programming Interfaces. It allows you to test the functionality of any application's APIs. Almost every developer uses Postman for testing purposes. We can create any type of HTTP request in it such as GET, POST, PUT, D
    2 min read
  • How to Handle a Post Request in Next.js?
    NextJS is a React framework that is used to build full-stack web applications. It is used both for front-end as well as back-end. It comes with a powerful set of features to simplify the development of React applications. In this article, we will learn about How to handle a post request in NextJS. A
    2 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, sof
    5 min read
  • How to send a POST Request with PHP ?
    In web development, sending POST requests is a common practice for interacting with servers and exchanging data. PHP, a versatile server-side scripting language, provides various approaches to accomplish this task. This article will explore different methods to send POST requests using PHP. Table of
    3 min read
  • How to perform DELETE requests in Postman?
    Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), save environments for later use, and convert the API to code for various languages(like JavaScript, and Python). In thi
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences