Use of Express application generator

Source: Internet
Author: User

First copy an article from the Express website:

(http://expressjs.com/en/starter/generator.html)

Express Application Generator

Use the application Generator tool,? express-generator, to quickly create a application skeleton.

The ? express-generatorPackageinstalls the? Expresscommand-line tool. Use the following command -to-do:

$ NPM Install Express-generator-g

Display the command options with the? - hoption:

$ 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

-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

For example, the following creates an Express app named? MyApp. The app would be created in a folder named? MyAppworking directory and the view engine would be set to? 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

Then install dependencies:

$ cd MyApp

$ NPM Install

On MacOS or Linux, run the app with this command:

$ debug=myapp:* NPM Start

On Windows, use the This command:

> Set debug=myapp:* & npm start

Then load? http://localhost:3000/your browser to access the app.

The generated app has the following directory structure:

.

├──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

?

It is important to note that:

    1. The path to the NPM needs to be added to the system's environment variables. Otherwise, the command line will not recognize the express command even if Express-generator is installed. You can restart the command line after adding the environment variable.

      The path to NPM is typically C:\users\<user NAME>\APPDATA\ROAMING\NPM

    2. Then follow the steps in the above article to execute, inside the-view can choose Jade, this I am more familiar with.

Use of Express application generator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.