[英]Can't reach localhost:PORT created in Node.js and express
require('dotenv').config();
const express = require('express');
const app = express();
const cors = require('cors');
app.use(cors);
const connectDB = require('./config/mongoDB');
const PORT = process.env.PORT || 8000;
// body parser
app.use(express.json({ extended: false }));
//router
app.use(
'/',
require('./routes/index')
);
app.listen(PORT, (req, res) => {
connectDB();
console.log('listening on port ' + PORT);
});
so this is my express server code, it was working yesterday but I can't reach localhost: PORT (via postman and browser) today but it is running and listening to PORT.所以这是我的快速服务器代码,它昨天在工作,但我今天无法访问 localhost: PORT(通过邮递员和浏览器),但它正在运行并侦听 PORT。 Where it goes wrong?哪里出错了?
cors
middleware should be called with parenthesis, as a function: cors
中间件应该用括号调用,作为一个函数:app.use(cors());
app.use(express.json({ extended: false }));
to:到:
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.