How to create a server in node.js

Pedro Antunes
Mar 19, 2021

If you read my previous tutorial How to make your first program in Node.js this one is quite easy.

Node.js allows us to easely create a HTTP server. To demonstrate it we will create a web page that show a simple message “Hello world!”

The first step is to create a Notepad++ file and type the following code:

Code to create a server

Then save your file as server.js.

The next step is to open Node.js command prompt, and after we change the directory, we will type the following command:

node server.js

The open your browser and go to the localhost:

http://127.0.0.1:8081

The output must look like the image below:

Output

--

--