The code below is what is wrong and it runs up until it gets to the .catch function with Mongo DB. And I can't figure out what is wrong. If i remove the catch and let it error it shall come up with this error -
(node:72993) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
//Dependicies
var express = require("express");
var mongoose = require("mongoose");
var bodyParser = require("body-parser");
var routes = require('./routes/route');
var app = express();
//MongoDB
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/filmo', { useMongoClient: true }, function () {
console.log("Connected to Database")
}).catch(function () {
console.log("Not Connected to Database ERROR!");
});
//Routes Listed
app.use('/', routes);
//Start Server
const defaultPortNumber = 8080
const port = process.env.PORT || defaultPortNumber
app.listen(port, err => console.log(err || `API is Running on port ${port}.`))
Added code to see what the error is actually saying via this link - How do I find out where an unhandled promise rejection occured?
And Error now says - MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]