1.安裝express應用生成器
$npm install express-generator -g #全局安裝
安裝成功如下-----2.express命令
C:\Users\Administrator>express -h
Usage: express [options] [dir]
Options:
-h, --help output usage information
-V, --version output the version number
-e, --ejs add ejs engine support (defaults to jade)
--hbs add handlebars engine support
-H, --hogan add hogan.js engine support
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sas
s) (defaults to plain css)
--git add .gitignore
-f, --force force on non-empty directory
3.生成應用
E:\test>express first -e
create : first
create : first/package.json
create : first/app.js
create : first/public
create : first/public/javascripts
create : first/public/images
create : first/routes
create : first/routes/index.js
create : first/routes/users.js
create : first/views
create : first/views/index.ejs
create : first/views/error.ejs
create : first/public/stylesheets
create : first/public/stylesheets/style.css
create : first/bin
create : first/bin/www
install dependencies:
> cd first && npm install
run the app:
> SET DEBUG=first:* & npm start
$cd first #進入first文件夾
$npm install #安裝依賴包
package.json:存儲項目的信息及模塊依賴,當在 dependencies 中添加依賴的模塊時,運行
npm
install
,npm 會檢查當前目錄下的 package.json,並自動安裝所有依賴模塊node_modules:存放 package.json 中安裝的模塊,當你在 package.json 添加依賴的模塊並安裝後,存放在這個文件夾下
public:存放 image、css、js 等文件
routes:存放路由文件
views:存放視圖文件或者說模版文件
bin:存放可執行文件
4.啓動應用
E:\test\first>npm start
> [email protected] start E:\test\first
> node ./bin/www