服务器永远加载,因为我对 server.js 使用以下代码

Server is loading forever as I use the following code for server.js

我在 server.js 文件中使用了此代码,在名为网站的文件夹中 app.js 中使用了主要代码。当我 运行 本地主机在终端中使用节点 server.js 并在浏览器中使用 运行 http://localhost:3000 时,它会永远加载而不会停止。

const bodyParser=require('body-parser');
const express=require('express');
const app=express();
/*dependencies*/
//Here we are configuring express to use body-parser as middle-ware.
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//cors for cross origin allowance
const cors=require('cors');
app.use(cors);
//making a local server
const port= 3000;
const server = app.listen(port, ()=>{console.log(`running on localhost: ${port}`)});
app.use(express.static('website'));

删除 CORS 模块。您可能不需要它,这也是无限加载的原因。如果需要,您可能应该搜索其他模块。