MongoDB can't connect to Server
Try this:
const express = require('express');const mongoose = require('mongoose');const bodyParser = require('body-parser');const app = express();// Bodyparser Middlewareapp.use(bodyParser.json());// DB Config// const db = require('./config/keys').mongoURI;const db = 'mongodb://mario:M010101@ds115963.mlab.com:15963/stack2709';// Connect to Mongomongoose .connect( db, { useNewUrlParser: true } ) // Adding new mongo url parser .then(() => console.log('MongoDB Connected...')) .catch(err => console.log(err));const port = process.env.PORT || 5000;app.listen(port, () => console.log(`Server started on port ${port}`));
I've already made this database just for you. As you can see here, everything is just fine.
Hopefully my answer helps!
The error said, another task is currently using the port 5000. Then, the solution is simple changing the port into something else. For example:
const port = process.env.PORT || 5050;
This is an alternative. If you're using Windows OS, try this:
In your Command Line:
netstat -aon | findstr :5000
You will get something like this:
Then:
taskkill /pid xxxxx /f
The xxxxx
need to be replaced with a process IDs
on the right side. Most of time, the top first pid
is the one we need.
By doing this, you will terminate the current task which is occupying the port 5000.