How to Create a Simple Server in Node.js that Display Hello World ? Last Updated : 17 Jun, 2024 Comments Improve Suggest changes Like Article Like Report We will create a simple server in Node.js that returns Hello World using an express server. Node.js is a powerful JavaScript runtime built on Chrome's V8 engine, commonly used to build scalable network applications. One of the fundamental tasks when learning Node.js is creating a simple server that responds with "Hello World." This article will guide you through the steps to set up such a server. Steps to Create Hello World Server in NodeStep 1: Initialize the NodeJS application using the following command npm initStep 3: express module which is a web framework for NodeJS in your project using the following commands. npm install expressThe updated dependencies in package.json file will look like: "dependencies": { "express": "^4.19.2" }Example: Implementation to create a server in nodejs. Node // app.js // Require would make available the // express package to be used in // our code const express = require("express"); // Creates an express object const app = express(); // It listens to HTTP get request. // Here it listens to the root i.e '/' app.get("/", (req, res) => { // Using send function we send // response to the client // Here we are sending html res.send("<h1> Hello World </h1>"); }); // It configures the system to listen // to port 3000. Any number can be // given instead of 3000, the only // condition is that no other server // should be running at that port app.listen(3000, () => { // Print in the console when the // servers starts to listen on 3000 console.log("Listening to port 3000"); }); Step to run the application: Run the app.js file using the following command. node app.jsOutput: Now open your browser and go to http://localhost:3000/, you will see the following output: outputSo this is how you can set up the server and achieve the task. If you want to return anything else then pass that argument in res.send() of the app.get() function instead of "Hello World". Comment More infoAdvertise with us Next Article How to Create a Simple Server in Node.js that Display Hello World ? D devrajkumar1903 Follow Improve Article Tags : Web Technologies Node.js NodeJS-Questions Similar Reads How To Create a Simple HTTP Server in Node? NodeJS is a powerful runtime environment that allows developers to build scalable and high-performance applications, especially for I/O-bound operations. One of the most common uses of NodeJS is to create HTTP servers. What is HTTP?HTTP (Hypertext Transfer Protocol) is a protocol used for transferri 3 min read How to Build a Simple Web Server with 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. Node.js is mostly used in server-side programming. In this article, we will discuss how to make 3 min read How to Create a Simple Server Using ExpressJS? The server plays an important role in the development of the web application. It helps in managing API requests and communication between the client and the backend. ExpressJS is the fast and famous framework of the Node.Js which is used for creating the server.In this article, we will create a simp 3 min read How to Create a Simple HTTP Server Listening at Port 3000 to Serve Video ? Creating a simple HTTP server to serve a video file can be done using various programming languages and frameworks. For simplicity, we'll use Python, which has built-in modules that make this task straightforward. In this article, weâll guide you through setting up a basic HTTP server using Python t 3 min read How to Serve Static Content using Node.js ? Accessing static files are very useful when you want to put your static content accessible to the server for usage. To serve static files such as images, CSS files, and JavaScript files, etc we use the built-in middleware in node.js i.e. express.static. Setting up static middleware: You need to crea 2 min read Like