Express 应用程序生成器
使用应用程序生成器工具—— express-generator 快速创建应用程序框架
安装 express-generator
$ npm install express-generator -g
使用 -h 选项显示所有命令选项
站位图片 express-h.jpg
例如,在当前工作目录创建名为 myapp 的项目
emmiter@mua:~/Sites/emmiter_github$ express myapp destination is not empty, continue? [y/N]如果
myapp已经存在也没关系,输入y回车继续执行即可
$ express myapp
create : myapp
create : myapp/package.json
create : myapp/app.js
create : myapp/public
create : myapp/public/javascripts
create : myapp/public/images
create : myapp/public/stylesheets
create : myapp/public/stylesheets/style.css
create : myapp/routes
create : myapp/routes/index.js
create : myapp/routes/users.js
create : myapp/views
create : myapp/views/index.jade
create : myapp/views/layout.jade
create : myapp/views/error.jade
create : myapp/bin
create : myapp/bin/www
install dependencies:
$ cd myapp && npm install
run the app:
$ DEBUG=myapp:* npm start
按照提示进入 myapp 目录,运行 npm install,然后在命令行输入 DEBUG=myapp:* npm start 启动应用。打开 http://localhost:3000 可以看到:
Express
Welcome to Express
P.S.
Windows 平台 run the app: 的命令是 set DEBUG=myapp:* & npm start
这样就生成了一个项目框架。这只是一种组织 express apps 文件的方式。可以根据自己项目的实际情况进行修改。