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