Framework is a top priority project, a team, you brought someone else's code can not be completely read through every byte, this time, using the framework, and that is our bridge of communication.
express one of many common generator frame. Help us quickly build a project.
His installation methods:
A: $ npm i express-generator -g (Global Installation)
Two: npx installation
use:
---- globally installed using: express -e
--- npx use: npx express -e
/ * Here -e representatives ejs type, as well as pug (formerly known as jade) and hbs
-e, --ejs add ejs engine support
--pug add pug engine support
--hbs add handlebars engine support */
First, realize the project directory structure 1.package.json look dependence: lowercase dependences production relies -S (after the project has been using is something dependent on production)
Uppercase D is the development of dependence. -D
After you find the start of the project file: bin / www
He's doing a server via http, the default port is 3000, and this document introduces a app file, the file is about createServer callback function put out. The use of a modular form, this file is the "entry file"
--- "Look app. js
express configuration (configured by the routing and express intermediate)
Route: The role can be done to create a link or interface pages
Middleware: Middleware is a function, a function for a particular feature
Middleware three types: 1. Application middleware Middleware 2. 3. routing error processing middleware
Build express:
routes folder write a xxx.js
const express=require('express');
const router=express.Router();
router.get('/home',function(req,res,next){
res.render('home',{
data:"zhangsan"
})
})
module.exports=router;
})
File folders establish xxx.ejs in views
Can write <h1> <% = data%> </ h1>
Terminal operation ( "node ./bin/www")
。。。。。。