Routing ( Routing ) is a URI of the (or call path) and a specific HTTP methods ( GET , POST , etc.) consisting of, related to how the application responds to the client access to a Web site node
Simple routing configuration
When using get when requesting access to a Web site, do something:
app.get("网址",function(req,res){ });
When a post when accessing a URL, do something:
app.post ( "URL", function (REQ, RES) { });
// user node to accept PUT requests
app.put('/user', function (req, res) { res.send('Got a PUT request at /user'); });
// user node accepts DELETE request
app.delete('/user', function (req, res) { res.send('Got a DELETE request at /user'); });
Dynamic routing configuration:
app.get( ,function(req,res){ var id = req.params["id"]; res.send(id); });
Routing regular match:
app.get('/ab*cd', function(req, res) {
res.send('ab*cd'); });
Routing inside Gets Get by value
app.get('/news, function(req, res) {
console.log(req.query);
});
Case:
/ * * * The Created by Administrator ON 2017/8/5 0005. * / / * 1.CD to the project which 2.npm init --yes / npm init create package.json 3. Express install npm install Express --save CNPM --save express the install 4. express introduced using var = express the require ( 'express'); var = new new App express () app.get ( '', function (REQ, RES) { }) * * * / var express = the require ( 'Express'); / * introducing * / var App = new new Express (); / * instantiate * / app.get ( '/', function (REQ, RES) { res.send ('Hello Express' ); }) app.get ( '/ News', function (REQ, RES) { res.send ( 'News module' ); }) app.get ( '/ Login', function (REQ, RES) { res.send ( 'log block' ); }) app.get ( '/ Register', function (REQ, RES) { res.send ( 'registration module' ); }) // POST // App. POST ( '/ doLogin', function (REQ, RES) { // // }) // dynamic routing app.get ( '/ newscontent /: AID', function (REQ, RES) { //req.params value acquired dynamic routing pass the console.log (req.params); var AID = req.params.aid; res.send ( 'newscontent module -' + AID); }) app.listen ( 3000, ' 127.0.0.1 ');