Assignment 2.1
//01
var express = require('express');
var app =express();
app.get('/',function(req,res){
res.send("Hello World")
})
//02
const express = require('express');
const app =express();
const port = 3000
app.get('/',function(req,res){
res.send("Hello World")
})
app.listen(port,() =>{
console.log('app listenting example on port ${port}')
})
//03
const express = require('express');
const app =express();
const port = 3000
app.get('/hello',function(req,res){
res.send("Hello Zaahid")
})
app.post('/hello',function(req,res){
res.send("Hello Zaahid")
})
app.listen(port);
//04
var express = require('express');
var app =express();
var things = require('./things');
app.use('/things', things);
app.listen(3000);
//05
var express = require('express');
var app= express();
app.get('/:id',function(req, res){
res.send("The id you specified is"+req.params.id);
});
app.listen(3000);
//06
var express = require('express');
var app= express();
app.get('/things/:name/:id',function(req, res){
res.send("ID:"+req.params.id + 'and name' +req.params.name);
});
app.listen(3000);
//07
var express = require('express');
var app= express();
app.get('/things/:id([0-9]{5})',function(req, res){
res.send("ID:" +req.params.id);
});
app.listen(3000);
//08
var express = require('express');
var app= express();
app.get('/things/:id([0-9]{5})',function(req, res){
res.send("ID:" +req.params.id);
});
//Other routes here
app.get('*', function(req, res){
res.send('Sorry, this is an invalid URL.');
});
app.listen(3000);
//09
var express = require('express');
var app = express();
app.use('/things', function(req, res, next){
console.log("A new request received at " + Date.now());
next();
});
app.get('/things', function(req, res){
res.send("Things");
});
app.listen(3000);
//10
var express = require('express');
var app = express();
app.use(function(req, res, next){
console.log("Start");
next();
});
app.get('/', function(req, res, next){
res.send("Middle");
next();
});
app.use('/', function(req, res){
console.log('End');
});
app.listen(3000);
Comments
Post a Comment