开发环境为VSCode1.32.3。
构建一个基本服务器
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('this is the homepage');
console.log('this is the homepage');
});
app.listen(3000);
console.log('listening to port 3000');
路由参数
var express = require('express');
var app = express();
app.get('/profile/:id/user/:name', function(req, res){//:id代表为任意字符串,且以id为其键
console.log(req.params);
res.send('You will see a profile with the id of ' + req.params.id);
});
app.get('/ab?cd', function(req, res){//路由匹配正则
res.send(' /ab?cd');
});
app.listen(3000);
console.log('listening to port 3000');
查询字符串
//http://127.0.0.1:3000/?find=hot req.query可以获取{find : 'hot'}
app.get('/', function(req, res){
console.dir(req.query["find"]);
res.send('here' + res.query.id);
});