How to create different post request using Node.js ? Last Updated : 25 Dec, 2020 Comments Improve Suggest changes Like Article Like Report A POST request is one of the important requests in all HTTP requests. This request is used for storing the data on the WebServer. For Eg File uploading is a common example of a post request. There are many approached to perform an HTTP POST request in Node.js. Various open-source libraries are also available for performing any kind of HTTP request. There are three approaches to create different post requests are discussed below. Using Needle ModuleUsing axiom ModuleUsing https Module Below all three approaches all discussed in detail: Approach 1: One of the ways of making an HTTP POST request in Node.js is by using the Needle library. Needle is a HTTP client for making HTTP requests in Node.js , multipart form-data (e.g. file uploads) , automatic XML & JSON parsing etc. Project structure: Installing module: npm install needle Index.js JavaScript //Importing needle module const needle = require('needle'); // Data to be sent const data = { name: 'geeksforgeeks', job: 'Content Writer', topic:'Node.js' }; // Making post request needle('post', 'https://requires.in/api/usersdata', data, {json: true}) .then((res) => { // Printing the response after request console.log('Body: ', res.body); }).catch((err) => { // Printing the err console.error(err.Message); } ); Execution command: node index.js Console Output: Approach 2: Another library that can be used is Axios. This is a popular node.js module used to perform HTTP requests and supports all the latest browsers. It also supports async/await syntax for performing a POST request. Installing module: npm install axios Index.js JavaScript // Importing the axios module const axios = require('axios'); // Data to be sent const data = { name: 'geeksforgeeks', job: 'Content Writer', topic: 'Node.js' }; const addUser = async () => { try { // Making post request const res = await axios.post( 'https://reqres.in/api/usersdata', data); // Printing the response data console.log('Body: ', res.data); } catch (err) { // Printing the error console.error(err.Message); } }; Execution command: node index.js Console Output: Approach 3: It is also possible to perform a POST request using Node.js built-in HTTPS module. This module is used for sending the data in an encrypted format Index.js JavaScript // Importing https module const https = require('https'); // Converting data in JSON format const data = JSON.stringify({ name: 'geeksforgeeks', job: 'Content Writer', topic:'Node.js' }); // Setting the configuration for // the request const options = { hostname: 'reqres.in', path: '/api/users', method: 'POST' }; // Sending the request const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); // Ending the response res.on('end', () => { console.log('Body:', JSON.parse(data)); }); }).on("error", (err) => { console.log("Error: ", err.message); }); // Write data to request body req.write(data); req.end(); Execution command: node index.js Console output: Comment More infoAdvertise with us Next Article How to create different post request using Node.js ? N naman9071 Follow Improve Article Tags : Web Technologies Node.js Node.js-Methods Similar Reads How To Make A GET Request using Postman and Express JS Postman is an API(application programming interface) development tool that helps to build, test and modify APIs. In this tutorial, we will see how To Make A GET Request using Postman and Express JS PrerequisitesNode JSExpress JSPostmanTable of Content What is GET Request?Steps to make a GET Request 3 min read How to create routes using Express and Postman? In this article we are going to implement different HTTP routes using Express JS and Postman. Server side routes are different endpoints of a application that are used to exchange data from client side to server side.Express.js is a framework that works on top of Node.js server to simplify its APIs 3 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 How to send different types of requests (GET, POST, PUT, DELETE) in Postman. In this article, we are going to learn how can we send different types of requests like GET, POST, PUT, and DELETE in the Postman. Postman is a popular API testing tool that is used to simplify the process of developing and testing APIs (Application Programming Interface). API acts as a bridge betwe 5 min read How to access Raw Body of a Post Request in Express.js ? Raw Body of a POST request refers to unprocessed or uninterpreted data sent in the request before Express or any middleware processes or understands it. It's like raw ingredients before the cooking begins. In this article we will see various approaches to access raw body of a post request in Express 3 min read How to Create a Pre-Filled forms in Node.js ? Pre-Filled forms are those forms that are already filled with desired data. These are helpful when a user wants to update something like his profile, etc. We just create a folder and add a file, for example, index.js. To run this file you need to run the following command. node index.js Filename: Sa 2 min read How to Generate or Send JSON Data at the Server Side using Node.js ? In modern web development, JSON (JavaScript Object Notation) is the most commonly used format for data exchange between a server and a client. Node.js, with its powerful runtime and extensive ecosystem, provides robust tools for generating and sending JSON data on the server side. This guide will wa 3 min read Different kinds of HTTP requests HTTP (Hypertext Transfer Protocol) specifies a collection of request methods to specify what action is to be performed on a particular resource. The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. These are equivalent to the CRUD operations (create, read, update, and d 5 min read How to send different HTML files based on query parameters in Node.js ? The following approach covers how to send different HTML files based on the query parameters in Node.js Approach: The task can be easily fulfilled by receiving the query parameters and map different HTML files with the respective parameters. Step 1: Create your project folder and install the express 2 min read Like