I. Installation and establishment of the project
1, installation Nodejs
2. Install Express (Global)
NPM Install-g Express
The default installation is 4.12.4
3, because the project builder is split separately after version 3.6, it also needs to be installed separately (global)
NPM install-g Express-generator
You can see the version of Express after you install it.
EXPRESS-V # Check the version of Express
4. Enter the working directory to create a project through Express
D:\>CD workspace/uedfe/www/express/&& express-e myexpress create:myexpress create:myexpress/ Package.json create:myexpress/app.js create:myexpress/public create:myexpress/public/stylesheets create:myexpress/public/stylesheets/ create:myexpress/public/images create:myexpress/views Create:myexpress/views/index.ejs create:myexpress/views/error.ejs create:myexpress/routes Create : Myexpress/routes/index.js create:myexpress/routes/users.js create:myexpress/bin Create: Myexpress/bin/www Install dependencies: > CD myexpress && npm install run the app: > SET debug=myexpress:* & npm start create:myexpress/public/javascripts
Express-e myexpress
This sentence I understand is the template for Ejs, if not with this parameter or-j that template will be used jade.
5. Enter the project directory and install the dependencies
Package.json files are automatically generated when the project directory is generated by express and need to be installed yourself
CD myexpress && NPM Install
6. Modify the Ejs template file suffix to html
Open App.js
Find--app.set (' View engine ', ' Ejs '); Replace with-->app.engine ('. html ', ejs.__express); App.set (' View engine ', ' html ');
and change the template file suffix in the View folder to HTML.
II. directory Structure
- Bin, the script file that holds the startup project
- Node_modules, store all project dependent libraries.
- Public, static file (css,js,img)
- Routes, routing files (C,controller in MVC)
- Views, page files (ejs templates)
- Package.json, Project dependent configuration and developer information
- App.js, applying the core configuration file
Third, start the service
NPM start
You can see the first page.
Nodejs Framework express4.x Learning--Installation Chapter