const srv = require('express')();
srv.listen(1208, () => {
console.log("Server running on port 1208!");
})
srv.listen(1209, () => {
console.log("Server running on port 1209!");
})
这会产生任何问题吗?同一实例可以侦听节点js中的多个端口吗?当我正常运行时,它运行正常!
此外,server.listen()通常是在服务器创建结束时编写的,我可以写这样的东西吗?
const srv = require('express')();
const abc = require('./routes/abc');
const def = require('./routes/def');
srv.listen(1208, () => {
console.log("Server running on port 1208!");
})
srv.use('/abc', abc);
srv.use('/def', def);
我可以先让服务器侦听,然后添加中间件吗?它可能带来什么变化/差异?