Node.js tutorial: Requesitions based on URL.

Pedro Antunes
Mar 20, 2021

If this is your first time using Node.js i sugguest you to check my previous tutorials How to make your first program in Node.js and How to create a server in node.js .

On this tutorial i will show you how Node.js can respond a requesition based on URL.

For this we will consider a computer store with the following categories:

>Laptops

>Smartphones

>Tablets

The JavaScript code to implement a service that can respond a requesition based on URL should be the following:

Index.js code

After we create the file above we name it as “index.js” then on the Node.js command prompt we execute the following command:

node index.js

The next step is open a browser and type the URL address to obtain its content.

To access the laptops category :

localhost:8080/portateis

Output

To access the smartphones category :

localhost:8080/smartphones

Output

To accessthe smartphones tablets:

localhost:8080/tablets

Output

--

--