const app = require('express')();
app.use((req, res, next) => {
// For example, a GET request to `/test` will print "GET /test"
console.log(`${req.method} ${req.url}`);
next();
});
app.get('/test', (req, res, next) => {
res.send('ok');
});
// Test the above app using Axios
const server = await app.listen(3000);
const axios = require('axios');
// Prints "get /test"
const res = await axios.get('http://localhost:3000/test');
1条答案
按热度按时间brvekthn1#
您可以在每次加载页面时使用
app.use
执行某些操作。请参阅此文档了解更多信息。https://masteringjs.io/tutorials/express/app-use