express http://expressjs.com提高开发效率 简单实例 var express = require('express'); var app = express(); app.get('/',function(req,res){ //获取url内参数 console.log(req.query); res.send('hello express'); }); app.listen(3000,function(){ console.log('app is running at port 3000'); }); 静态资源 //默认指定静态文件夹,浏览器直接可以访问(开放资源) //app.use(express.static('./public/'))可以省略public来访问 app.use('/public/',express.static('./public/')); 路由 url映射关系(请求路径+请求方法)新增文件router.js //router.js app .get('/',function()) .get('/index',function()) .post('/',function()) art-template npm install --save art-templatenpm install --save express-art-template //配置使用art-template模板 //第一个参数表示渲染.art文件的时候使用模板引擎渲染 //res.render('html模板',{数据});//渲染 //将视图文件放入views目录,render默认读取views //app.set('views',修改的默认路径) app.engine('art',require('express-art-template')); 获取post数据 没有内置获取post数据的api,需要第三方中间件body-parsernpm install --save body-parservar bodyParser = require(‘body-parser’);app.use(bodyParser.urlencoded({extended:false}))req.body即为post提交数据 自动加载重启 npm install --global nodemon 安装 nodemon app.js 启动服务,文件变化会自动加载重启