I have an EC2 Instance, it runs Ubuntu, CyberPanel, Node v 14.4.0. I created a website using the normal CyberPanel options and edited the context menue in OLS (:7080) to run node. The website runs fine but the moment I try to connect it with my MongoDB instance either using Mongoose or the native MongoDB Driver, the website stalls.
I can't access the error logs as well. However, when I remove the code that requires MongoDB, and restart the server, the website works. Any solutions?
const express = require('express'),
app = express(),
ejs = require('ejs'),
bodyParser = require('body-parser'),
db = require('./models'); //I use mongoose = require('mongoose') here
port = process.env.PORT || 3000;
const blogRoutes = require('./routes/blogAPI');
const portfolioRoutes = require('./routes/portfolioAPI');
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(__dirname + "/public"));
app.get('/', function(req, res){
db.portfolio.find().then(function(portfolio) {
data = [...portfolio];
res.render('home', data);
}).catch(function(err){
res.send(err);
})
});