0

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);
    })
});
  • could you provide the import file of mongodb ? – mohammad Naimi Sep 19 '21 at 16:32
  • Hey, not sure where to get the import file. I simply did, npm i mongodb and then require it to the project. In case you are asking about the MongoDB instance, that is a cloud atlas cluster made on MongoDB website itself. That instance is open to all IPs and it works in my local machine. – Indraprastha Design Sep 21 '21 at 03:56

0 Answers0