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次に依存関係をインストール:
$ cd myapp$ npm install