I am trying to dockerize my node.js app and it just won’t work. I narrowed the point of error down to two lines, but I just can’t get to the ground of the problem. I’ll share my code if you need more just ask for it. I am using a raspberry pi 3 to deploy my container unsing portainer. Maybe I missed a setting there idk.
console.log("Hello from the docker3")
//Database
const mongoose = require("mongoose");
mongoose.connect(
`mongodb+srv://{process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_ADDRESS}/`
);
console.log("Hello from the docker4")
The rest of the code are just some webpages that get sent and some express.js stuff.
I am getting this error from this part, you can see that the print number 4 doesn’t get printed so I think it’s somewhere there
I searched everywhere but I couldn’t find a reason for this.
2
Answers
Can you modify your connection code to log any errors that occur during the connection process. This can provide more insight into what’s happening :
mangoose return promise object and if we want to get response from promise object either we have to use await or then Try following ways
Ensure that the environment variables (DB_USER, DB_PASSWORD, DB_ADDRESS) are set correctly. You can print these values to the console to verify if they are being correctly retrieved from the environment: