Express-generator

Express 應用生成器

通過應用生成器工具 express 可以快速創建一個應用的骨架。

1.通過如下命令安裝:
$ npm install express-generator -g

-h 選項可以列出所有可用的命令行選項:

$ 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|sass) (defaults to plain css)
        --git           add .gitignore
    -f, --force         force on non-empty directory
2.下面的示例就是在當前工作目錄下創建一個命名為 myapp 的應用。
$ express myapp

  warning: the default view engine will not be jade in future releases
  warning: use `--view=jade' or `--help' for additional options


   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   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
   create : myapp/public/images
   create : myapp/public/javascripts
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css

   install dependencies:
     $ cd myapp && npm install

   run the app:
     $ DEBUG=myapp:* npm start

3.然后安裝所有依賴包:
$ cd myapp 
$ npm install
4.啟動這個應用

MacOS 或 Linux 平臺:

$ DEBUG=myapp npm start

Windows 平臺使用如下命令:

set DEBUG=myapp & npm start
5.然后在瀏覽器中打開 http://localhost:3000/ 網址就可以看到這個應用了。
6.通過 Express 應用生成器創建的應用一般都有如下目錄結構:
.
├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.jade
    ├── index.jade
    └── layout.jade

7 directories, 9 files
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容