這裏我將貼出核心代碼html
app.js 文件以下express
app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); app.use('/users', users); app.use('/login', routes);//此到處理登錄
路由(routes)文件下的index文件json
var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { //res.render('index', { title: 'Express' }); res.sendfile("./views/index.html"); }); router.get('/login', function (req, res, next) { res.render('login',{ title: '登陸頁面' }); // res.sendfile("./views/login.html"); });
視圖文件(views)文件夾下的jade改成htmlcookie
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <table> <h1><%=title%></h1> <tr> <td >用戶名</td> <td><input type="text" name="name" value=""></td> </tr> <tr> <td >密碼</td> <td><input type="text" name="pwd" value=""></td> </tr> </table> </body> </html>