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 JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read JavaScript Interview Questions and Answers JavaScript (JS) is the most popular lightweight, scripting, and interpreted programming language. JavaScript is well-known as a scripting language for web pages, mobile apps, web servers, and many other platforms. Both front-end and back-end developers need to have a strong command of JavaScript, as 15+ min read React Tutorial React is a JavaScript Library known for front-end development (or user interface). It is popular due to its component-based architecture, Single Page Applications (SPAs), and Virtual DOM for building web applications that are fast, efficient, and scalable.Applications are built using reusable compon 8 min read Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w 8 min read REST API Introduction REST API stands for REpresentational State Transfer API. It is a type of API (Application Programming Interface) that allows communication between different systems over the internet. REST APIs work by sending requests and receiving responses, typically in JSON format, between the client and server. 7 min read NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net 15+ min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read What is an API (Application Programming Interface) In the tech world, APIs (Application Programming Interfaces) are crucial. If you're interested in becoming a web developer or want to understand how websites work, you'll need to familiarize yourself with APIs. Let's break down the concept of an API in simple terms.What is an API?An API is a set of 10 min read Like