Web
Analytics
express router tutorial | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

express router tutorial

Basic setup command

npm init
npm install express

 

var express = require('express');
var myrouter = express.Router();

myrouter.get('/', function(req, res){
   res.send('Get Route without parameter');
});
myrouter.get('/about', function(req, res){
    res.send('About Get Request');
 });
myrouter.post('/', function(req, res){
   res.send('POST Request');
});
myrouter.get('/users/:id', function(req, res){
    console.log(req.params);
    res.send('Get Request with id parameter');
 });
//export this router to use in our index.js
module.exports = myrouter;





var express = require('Express');
var app = express();

var myroutes = require('./myroutes.js');

app.use('/myroutes', myroutes);

app.listen(3000);