How to Use Express Generator

作者: shisaq 日期: January 31, 2017

Express generator is a tool that helps quickly generate your application skeleton.

Preparation

  • Have Node.js with npm installed

Installation

npm install express-generator -g

Now if you type express -h, you’re able to get the help list below.

help

One Step Generation

express myapp

This command will simply generate the application folder called myapp for you by default config. After having done this, you can:

  • cd myapp && npm install
  • npm start
  • Open your browser, type localhost:3000, you can see the server is running

generate

Customize Config

express myapp --hogan -c less

This command shows we use a template called hoganJS, and install Less as a middleware of CSS.

Pay attention: the newest express generator recommand us to use --view=templateName to replace --templateName, but actually, the key point that leads to success or fail depends on which template you pick. For instance, you can use express myapp --view=jade; but you have to use express myapp --hogan instead. For more info, check the instruction by typing express -h.