How to create a simple server in Node.js that display Hello World ?
In the following example, we will create a simple server in Node.js that returns Hello World using an express server.
Create NodeJS Application: Initialize the NodeJS application using the following command:
Module Installation: Install the express module which is a web framework for NodeJS using the following command.
npm install express
Implementation: Create an app.js file and write down the following code in it.
Step to run the application: Run the app.js file using the following command.
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
So 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”.