I am following this MERN tutorial: https://www.youtube.com/watch?v=ngc9gnGgUdA Around @18:00 is where I am having problems. After some research I think some of the code in the video is outdated and I am doing my best to get this to work! This is my current error: Error: listen EADDRINUSE: address already in use :::5000
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';
import postRoutes from './routes/posts.js';
const app = express();
app.use('/posts', postRoutes);
app.use(bodyParser.json( { limit: "30mb", extended: true}));
app.use(bodyParser.urlencoded( { limit: "30mb", extended: true}));
app.use(cors());
const CONNECTION_URL = 'mongodb+srv://test:test123@cluster0.mql8u.mongodb.net/myFirstDatabase?retryWrites=true&w=majority';
const PORT = process.env.PORT || 5000;
mongoose.createConnection(CONNECTION_URL).asPromise();
mongoose.connect(CONNECTION_URL)
.then(() => app.listen(PORT, () => console.log(`server running on port: ${PORT}` )))
.catch((error) => console.log(error.message));
I SUPER appreciate any and all help. If anyone can point me in the direction of a better tutorial that would be amazing! I am a novice code, I finished a virtual coding bootcamp recently, but I need to make some real apps. Thanks again!
First I would check and see if you already have something running on port 5000, to confirm, I would run npx kill-port 5000, then try to run port 5000 again to see if that port is now free after killing it via the previously noted command...