小编Adi*_*han的帖子

Nodejs with express:为什么我的中间件执行两次这里是代码

这是我的代码在这里..!

const express = require('express');
const app = express();

let myFunc = function (req, res, next) {
    console.log('This is middleware');
    next();
}

app.use(myFunc);

app.get('/', (req, res) => {
    console.log('This is get /');
    res.send('Hello World!');
});

app.listen(3000, () => {
    console.log('Server is running at port 3000....');
});
Run Code Online (Sandbox Code Playgroud)

在此,我创建了一个名为 myFunc 的中间件,但输出并不像我想象的那样

Server is running at port 3000....
This is middleware
This is get /
This is middleware
Run Code Online (Sandbox Code Playgroud)

javascript middleware node.js express

3
推荐指数
2
解决办法
3066
查看次数

标签 统计

express ×1

javascript ×1

middleware ×1

node.js ×1