express route not sending html code example
Example 1: route parameter in node
var express = require('express');
var fs = require('fs');
var app= express();
app.get('/index/profile/:id',function(req,res){
// res.send('profile with id' + req.params.id)
});
app.listen(3000,'127.0.0.1');
console.log('lsitng');
Example 2: node express dynamic route and error handler
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
Example 3: express() vs express.router()
var express = require('express'),
dogs = require('./routes/dogs'),
cats = require('./routes/cats'),
birds = require('./routes/birds');
var app = express();
app.use('/dogs', dogs);
app.use('/cats', cats);
app.use('/birds', birds);
app.listen(3000);
Example 4: express() vs express.router()
var express = require('express');
var router = express.Router();
router.get('/', function(req, res) {
res.send('GET handler for /dogs route.');
});
router.post('/', function(req, res) {
res.send('POST handler for /dogs route.');
});
module.exports = router;