In fact, the routing methods can have more than one callback function as arguments. With multiple callback functions, it is important to provide next
as an argument to the callback function and then call next()
within the body of the function to hand off control to the next callback.
index.js
var express = require('express');
var app = express();
app.get('/hello', function(req, res){
res.send("Hello World!");
});
app.listen(3000);
http://localhost:3000/hello
index.js
var express = require('express');
var path = require('path');
var app = express();
app.get('/hello', function(req, res){
res.send("Hello World!");
});
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, 'read.html'));
});
app.listen(3000);
http://localhost:3000
index.js
var express = require('express');
var path = require('path');
var app = express();
app.get('/hello', function(req, res){
res.json({
'name' : "Pankaj Kumar Loniya",
'age': 28,
'Branch': 'EEE'
});
});
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, 'read.html'));
});
app.listen(3000);
http://localhost:3000/hello