( Review by yourself )
One 、 Create scaffolding sudo npm i express-generator -gmkdir express-clicd express-cliexpress express-testnpm intsallnpm start
Two 、 The second step ( I don't know what title )
nodemon Monitoring code file changes , Restart at any time cross-env Don't worry about platform settings or using environment variables npm i nodemon cross-env --save-dev
bin: Compiled executable file
www To provide a http Service for .
publick 、views Front end with .
// package.json
"dev": "cross-env NODE_ENV=dev nodemon ./bin/www"
3、 ... and 、 Introduce express Entry file
The role of each plug-in .
var cookieParser = require('cookie-parser'); analysis cookievar logger = require('morgan'); For logging
app This time http Instance of request
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;
Four 、 Demonstrates how to handle routing
New route file user.js,
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.post('/login', function (req, res, next) {
const { username, password } = req.body;
res.json({
error: 0,
data: {
username,
password
}
})
});
module.exports = router;
poatman Request mode :
5、 ... and 、 Middleware mechanism
put questions to :
- There's a lot of
app.use... - In the code next ginseng
// middleware , The function in the middle .
// Yes likeLogin, If you have any res return , The following function is not executed
function likeLogin(req, res, next) {
console.log(" Successful simulation login ");
res.json({
error: 0,
data: [1, 2, 3]
});
}
app.use('/api', likeLogin, (req, res, next) => {
console.log("/api app.post");
next();
})
6、 ... and 、express summary :
How to handle logs ,cookie,
How to deal with routing ,
How to use middleware
7、 ... and 、 Build a blog system 



![[论文阅读笔记] Community-oriented attributed network embedding](/img/17/1d1989945d943ca3cd2a2b8a5731de.jpg)
![[C#.NET 拾遗补漏]11:最基础的线程知识](/img/5f/3db6e0620191da4893ad7b4e2ba064.jpg)