前提条件
- 安装nodejs运行环境
- 安装express
安装插件
npm install -g express
npm install -g express-generator
创建项目
E:\NodeStu>express demo
warning: the default view engine will not be jade in future releases
warning: use `--view=jade' or `--help' for additional options
create : demo
create : demo/package.json
create : demo/app.js
create : demo/public
create : demo/views
create : demo/views/index.jade
create : demo/views/layout.jade
create : demo/views/error.jade
create : demo/routes
create : demo/routes/index.js
create : demo/routes/users.js
create : demo/bin
create : demo/bin/www
create : demo/public/javascripts
create : demo/public/images
create : demo/public/stylesheets
create : demo/public/stylesheets/style.css
install dependencies:
> cd demo && npm install
run the app:
> SET DEBUG=demo:* & npm start
进入demo目录后执行命令
E:\NodeStu>cd demo
E:\NodeStu\demo>npm install
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
npm notice created a lockfile as package-lock.json. You should commit this file.
added 103 packages in 2.939s
E:\NodeStu\demo>npm start
> demo@0.0.0 start E:\NodeStu\demo
> node ./bin/www
测试访问
在浏览器输入地址:
http://127.0.0.1:3000
注意事项
需要两个插件都安装才能使用express命令。