默认已经安装了最新的node.js
第一步:建造一个文件夹myApp,在文件夹根目录下执行命令
npm init
生成一个package.json的文件
第二步:下载express模块 --save的作用是将express保存到依赖列表中
npm install express --save
第三步: 在文件夹下建一个新文件“app.js”,这是入口文件
输入试例代码
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
第四步: 运行app.js文件

在浏览器中打开

框架安装完啦!
原始的文档结构

常见问题解决方法:
1 中文在浏览器中乱码,在响应的数据格式中添加charset=utf-8
》》 reponse.writeHead(200,{"Content-Type":"text/plain;charset=utf-8"})
官网网址:http://www.expressjs.com.cn/starter/installing.html
中文教程网址: http://www.ybao.org/book/express/5409.html
github上的开源项目 https://github.com/WebCodeFarmer/express
网友评论