Hy guys, it is possible connect cloud mongodb in cPanel. Now I have server error 502 , as I understand its mongoDb fault.I'm not very good at this stuff, deploy projects.
My code:
const PORT = --PORT;
const hostname = --hostname;
const DB_URL = 'mongodb+srv://user:password@cluster0.4ie8h.mongodb.net/bootcamp?retryWrites=true&w=majority';
async function start(){
try{
mongoose.connect(DB_URL, {
useUnifiedTopology: true,
useNewUrlParser: true,
autoIndex: true,
})
app.listen(PORT, hostname, () => { console.log('Server started on port ' + PORT)});
}catch(e){
console.log(e);
}
}
start();
Your code seems to be absolutely correct. Keep in mind that "502" is usually a "Bad Gateway" error which means that most probably your web service is not forwarding properly the request to the correct port of your app. Make sure that you have in place the correct rewrite rules inside your .htaccess file for that. Your web hosting provider should be able to help with that.