Node.js tutorial: how to use Epress.js

In the last tutorial we showed how to create requests based on the URL: Node.js tutorial: Requesitions based on URL.

In this tutorial we gona use Express.js to make the same operations in a easier away.

Express.js is a framework for Node.js that allows us develop web applications in a easier away.

How to instal Express.js?

First we open Node.js command prompt and change the directory for the one we are working on, then type the following command:

npm install express -save

After the instalation the command prompt should look like this:

command prompt

Now considering the last tutorial the notepad++ file should contain the following code:

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

Computer science student