Route setting method for Expressjs
First, the basic method:
App. METHOD (PATH, HANDLER)
The path and method of action (which can be HTTP get/put/delete, etc.) are mapped to a handler function handler
For example:
App.get ('/user ', function (req, res) {
Res.send (' Got a PUT request At/user ');
});
Second, use Express. Methods of Router
Defines a set of paths. For example:
/birds
/birds/about
1) First in the router file, define only relative paths/and/about
var express = require (' Express ');
var router = Express. Router ();
Define the home page route
Router.get ('/', function (req, res) {
Res.send (' Birds home page ');
});
Define the About route
Router.get ('/about ', function (req, res) {
Res.send (' About birds ');
});
Module.exports = router;
2) in the main file, define the base path/birds,
var birds = require ('./birds ');
App.use ('/birds ', birds);
Settings for router in Expressjs server