Express

const express = require('express'); const path = require('path'); const bodyParser = require('body-parser'); const crypto = require('crypto'); // 生成一个 express 实例 const app = express(); // 设置视图文件存放目录 app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // 设置静态文件存放目录 app.use(express.static(path.join(__dirname, 'public'))); // 解析 urlencoded 请求体必备 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); // 响应首页get请求 app.get('/', function(req, res) { res.render('index', { title: '首页' }); }); app.get('/login', function(req, res) { res.render('login', { title: '登录', user: req.session.user, page: 'login' }); }); app. [Read More]