I've been troubleshooting an issue with my simple express app and I can't seem to figure out why it's not loading in any web browser or in Postman. Even though port 3000 doesn't appear to be in use, changing ports still results in the same error. The console logs show no errors except for ERR_CONNECTION_REFUSED across all apps. Below is a snippet of my JavaScript code, with a separate .env file specifying PORT = 3000.
require('dotenv').config()
const express = require("express");
const app = express();
app.use('/places', require('./controllers/places'))
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.get('*', (req, res) => {
res.status(404).send('<h1>404 Page </h1>')
})
app.listen(process.emitWarning.PORT);
const PORT = process.env.PORT;
app.listen(PORT, () => {
console.log("App running on port 3000");
});
I have already tried npm install, npm init, and nodemon which starts the server successfully with "App running on port 3000" message displayed in the terminal. However, trying to access the app in different browsers leads to the same outcome. I have disabled my firewall, cleared DNS cache, and browser cache in multiple browsers but the issue remains unresolved. Please advise on any further steps needed! Your help is highly appreciated.