NodeJS 如何解决错误:TypeError:app.listen不是函数

soat7uwm  于 2023-05-28  发布在  Node.js
关注(0)|答案(2)|浏览(204)

我是node.js的新手,我正在做我的第一个项目。我得到了错误TypeError:app.listen不是启动应用程序时的函数。请问您能帮助我们解决这个问题吗?
下面是我的app.js

const express = require("express");
const routes  = require("./routes/index");

const app = express();
app.use('/',routes);

module.exports = app;

routes/index.js

const express = require("express");
const router = express.Router();
router.get('/',(req,res) => res.send("It works!!"));
module.exports = router;

start.js

const app = require("./app");
const server = app.listen(3000, () => {

    console.log('Express is running on port ${server.address().port}');
});
6psbrbz9

6psbrbz91#

const express = require('express');
const app = express();
app.listen(Port, () => {
  console.log(`Server running on port ${Port}`);
})
jucafojl

jucafojl2#

用这个

const PORT = process.env.PORT || 5000;
app.listen(PORT);

相关问题