node.js: How to use express.js

Hi people!!

Today I will demonstrate how to use express.js.

The express.js is a framework for web applications for Node.js.

1st step: Open the command line and enter the following commands:

mkdir URL_req
npm init
touch express.js
npm install express -save

2nd step: Insert the following code

var express = require('express');var app = express();app.get('/',function(req, res) {res.send("Technology's Store");});app.get('/laptops',function(req,res){res.send("Laptops Category");});app.get('/smartphones',function(req,res){res.send("Smartphones Category");});app.get('/tablets',function(req,res){res.send("Tablets Category");});app.listen(8088,function(){console.log("Servidor ativo no porto 8088");});

3rd step: Run the following command

node express.js

And these were the results:

http://localhost:8088/
http://localhost:8088/laptops
http://localhost:8088/smartphones
http://localhost:8088/tablets

I hope you enjoyed!!

--

--