var express = require('express'); var app = express(); var comments = [ { name:'姓名', message:'你好呀', dateTime:'2018-12-12' } ] app.set('views','./common/'); app.engine('html', require('express-art-template')); app.set('view options', { debug: process.env.NODE_ENV !== 'production' }); app.use('/public/',express.static('./public/')); app.get('/',function(req,res){ //express会到默认的views目录下去找该文件 //修改默认views目录,app.set('views','./common/') res.render('index.html', { comments:comments }) }); app.get('/post',function(req,res){ res.render('post.html'); }); app.get('/ping',function(req,res){ var common = req.query; common.dateTime = '2018-12-12'; comments.unshift(common); res.redirect('/'); }) app.listen(3000,function(){ console.log('running...'); })