安装
首先保证自己已经安装过Node,才能安装Express。
安装Express
npm install express -g
安装Express生成器
npm install express-generator -g #检测是否安装正确 PS C:\WINDOWS\system32> express -h Usage: express [options] [dir] Options: --version output the version number -e, --ejs add ejs engine support --pug add pug engine support --hbs add handlebars engine support -H, --hogan add hogan.js engine support -v, --view <engine> add view <engine> support (dust|ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade) --no-view use static html instead of view engine -c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css) --git add .gitignore -f, --force force on non-empty directory -h, --help output usage information
创建项目
#一般安装ejs模板 express -e myfirstexpress #安装模块 npm install body-parser --save npm install cookie-parser --save npm install multer --save
body-parser : node.js 中间件,用于处理 JSON, Raw, Text 和 URL 编码的数据。
cookie-parser : 这就是一个解析Cookie的工具。通过req.cookies可以取到传过来的cookie,并把它们转成对象。
multer : node.js 中间件,用于处理 enctype="multipart/form-data"(设置表单的MIME编码)的表单数据。
运行项目
cd myfirstexpress npm start > myfirstexpress@0.0.1 start /root/myfirstexpress > node ./bin/www
访问项目
然后在自己的浏览器中输入 :http://localhost:3000
还没有评论,来说两句吧...