2018-12-07复习
express
//1.创建服务器
// 下载:npm install express
const express=requie('express');
//2.创建一个静态文件目录
// cnpm install express-static
const expressStatic=require('express-static');
//5.处理用户的post请求 中间件 body-parser
const bodyParser=require('body-parser');
//cookie-parser
const cookieParser=require('cookie-prase');
//cookie-session
const cookieSession=require('cookie-session');
var server=express();
server.use(bodyParser.urlencoded());
server.use(cookieParser())
server.use(cookieSession({
keys:['asads','fvgfd','dfgfdg'];
}))
//3.如何处理用户的请求
server.use('/1,html',function(req,res){
res.send('fdfdfdb');
res.end();
//4.处理客户的get请求
console.log(req.query);
//5.处理客户的post请求
console.log(req.body);
})
//6.链式操作:
server.use('/',function(req,res,next){
console.log('a');
next();
});
server.use('/',function(req,res){
console.log('b');
})
//发送cookie
server.use('/',function(req,res){
res.cookie('user','jack')
})
//获取cookie
server.use('/',function(req,res){
console.log(req.cookies);
res.send('200');
})
//cookie加密
server.use('/',function(req,res){
res.secret='fdbgdfdfbfdgf';
res.cookie('user','jack',{signed:true})
res.send('200');
});
//session
server.use('/',function(req,res){
console.log(req.session)
})
server.listen(8080);
server.use(expressStatic('./www'))