Express應用生成器

通過應用生成器工具express可以快速創建一個應用的骨架。通過如下命令安裝:

sudo 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

使用express myapp 命令就可以創建一個myapp的應用:

express myapp

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

   install dependencies:
     $ cd myapp && npm install

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

然後安裝所有依賴包:

$ cd myapp 
$ npm install

啓動這個應用(MacOS 或 Linux 平臺):

$ DEBUG=myapp npm start

Windows 平臺使用如下命令:

> set DEBUG=myapp & npm start

然後在瀏覽器中打開 http://localhost:3000/ 網址就可以看到這個應用了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章