Express 生成器

使用应用程序生成器工具 express-generator 快速创建应用程序骨架。

您可以使用 npx 命令(在 Node.js 8.2.0 中可用)运行应用程序生成器。

$ npx express-generator

对于较早的 Node 版本,将应用程序生成器安装为全局 npm 包,然后启动它:

$ npm install -g express-generator
$ express

显示带有 -h 选项的命令选项:

$ express -h

  Usage: express [options] [dir]

  Options:

    -h, --help          output usage information
        --version       output the version number
    -e, --ejs           add ejs engine support
        --hbs           add handlebars engine support
        --pug           add pug engine support
    -H, --hogan         add hogan.js engine support
        --no-view       generate without view engine
    -v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
    -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

例如,以下创建一个名为 myapp 的 Express 应用程序。该应用程序将在当前工作目录中名为 myapp 的文件夹中创建,并且视图引擎将设置为 Pug

$ express --view=pug myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.pug
   create : myapp/views/layout.pug
   create : myapp/views/error.pug
   create : myapp/bin
   create : myapp/bin/www

+6NPii3jh414LHx2L3PtaxZgdz8L92JqBam4XNy+U+A=

$ cd myapp
$ npm install

K7hu8hlmS+PoLNXn4stOSQnnxt6AKqkicqVdeqSIJ2r+f5q3yVpsNsD3T6wO2LXk3FLHGYB7i1Xk/B3RPja4rnbllUOVLCrqARBlxrV7dwM=

$ DEBUG=myapp:* npm start

kdUazsdcznjm1mUEnJgX8F9GJcykwMUo3GrHMFMmkYlBN+tqPzPXWRTkPp3urhtse+Fi3WZ0WSEsCdHC7g8DTw==

> set DEBUG=myapp:* & npm start

udvuPufjPGaT9sA9oFCTntqduBPbPnyOh3SIvsy3Flsr7urXPFvrf0Xi+KPaCL9vrtMei96Yv7wSO9+dd2jxbA==

PS> $env:DEBUG='myapp:*'; npm start

8ZTI2z+FNcre1i1V1Kr9k1B/djhWRwCDuWud9BxRm/ztxn2OfhvHrsDku96AtDJcB3PPXDX/qr6QSHkurBCkDS9NBKRBvEwoqxc0iNf2VPHYH/FAg0sJAPPayCLwqUG2

aba2ayxZu+/i+dp/cAOhtqyVyZuIJfKv+8Ktl2d2iAyFgQqfDZQMueipIIspk52BXt6yVsGVAVJ8/HCIVtrkDw==

.
├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.pug
    ├── index.pug
    └── layout.pug

7 directories, 9 files

bamYNA1ARYQpyAYIM/fMm+GGSU1RKUmcRKIMLD36Zd7AguQjXsvFCP9DZ/XcrI6UXBz4UCtZNqA/Q4mgXj6Gq+iC/AK2Gb81tf6WHxxmq4FQfIzABQvefKOpgld7Optt6rlSBHTBLE89y9Ll3HtE5TM1LUYn7vTvsN0nwAnbkWecRmLA0OBi/bRLVPddZHLjuk3A9nFOiCLsdPsqrF/7nwWB3Xsz5kFPPtXa5Xv+FMM=