我遇到了没有回复的中间件问题。我已经搜索过这个问题,但无法找到解决此问题的适用解决方案。
import express from 'express';
const app = express();
app.use(function log(req, res, next) {
console.log('logging with fun...');
next();
});
console.log('Help help help ...');
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`Listening on port: ${port}`));
请指导,我犯错了,因为我只是在控制台输出如下:
帮助帮助...
聆听端口:3000
答案 0 :(得分:0)
您正确添加了中间件,但未创建任何路由。
您的代码将变为
import express from 'express';
const app = express();
app.use(function log(req, res, next) {
console.log('logging with fun...');
next();
});
// Just add any route.
app.get('/',function log(req, res) {
res.send('Hello');
});
console.log('Help help help ...');
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`Listening on port: ${port}`));
现在导航到
http://localhost:3000/