Node.js tutorial: Requesitions based on URL.

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:




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

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 :


To access the smartphones category :


To accessthe smartphones tablets: