When I use mongoose on my laptop with localhost, it doesn't show any errors with connecting to the database but when I move the app to the production URL, it returns a {}. Please what could be the cause of the error and the best possible fix? I'm already getting frustrated as it is.
Here's a bit of my code:
const express = require ('express'),
mongoose = require ("mongoose"),
Model = require("././models/model"),
bodyParser = require('body-parser'),
app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
require('dotenv').config({ path: './.env'});
app.use(bodyParser.urlencoded({extended: true}));
//ROUTES
app.get('/', function(req, res){
res.render("index")
})
app.post('/', function(req, res){
var main= new Model({
from: req.body.from,
to: req.body.to,
amount: req.body.amount,
description: req.body.description
})
main.save(function(err, mainModel){
if (err){
res.send(err)
}else{
res.redirect('/')
}
})
})
mongoose.set('useFindAndModify', false);
mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true, useUnifiedTopology: true });
app.listen(process.env.PORT || 8080, function(){
console.log("APP IS RUNNING!!!")
})
P.S: Everything works on my laptop and the post request redirects to '/' but on the production URL, the post request is not completed and it redirects to an empty page with just {}. I'm using a live DB for process.env.DATABASEURL
question from:
https://stackoverflow.com/questions/66062988/mongoose-not-connecting-on-production-site 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…