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

Time:11-13

I have used this code in server.js file and the main code in app.js in folder called website. when i run localhost using node server.js in terminal and run http://localhost:3000 in browser, it is loading forever with no stopping.

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'));

CodePudding user response:

Remove the CORS module. You probably don't need it and its the reason for the infinite loading. If you need it, you should probably search for a different module.

  • Related