terminal after trying to run server server
const express = require('express')
const colors = require('colors')
const dotenv = require('dotenv').config()
const {errorHandler} = require('./middleware/errorMiddleware')
const connectDB = require('./config/db')
const port = process.env.PORT || 5000
connectDB()
const app = express()
app.use(express.json())
app.use(express.urlencoded({extended: false}))
app.use('/api/goals', require('./routes/goalRoutes') )
app.use(errorHandler)
app.listen(port, () => console.log(`Server started on port ${port} `) )
CodePudding user response:
There is already an application listening on port 5000, like the error message suggests. Close any other command prompt/bash that may be running an instance of the application and try again.
CodePudding user response:
Port 5000 is already in use by another application. Either close this port or choose an unused port by:
Changing: const port = process.env.PORT || 5000
to const port = process.env.PORT || <otherport>
or by providing an unused port as an environmental variable.