As I mentioned in the title, sorry because this is a duplicate question, but literally any of given possible solutions doesn't work. To be specific, I created .env file which constists of 2 variables, username and password (which are from created projects, not from mongodb login page):
const uri = `mongodb+srv://${mongo_username}:${mongo_password}@cluster0.whz2jow.mongodb.net/?retryWrites=true&w=majority`;
const mongo_username = process.env["MONGO_USERNAME"];
const mongo_password = process.env["MONGO_PASSWORD"];
When I try console.log that two it really works. But then when I want to connect:
MongoClient.connect(uri, {
maxPoolSize: 50,
//wtimeoutMS: 2500,
useNewUrlParser: true,
useUnifiedTopology: true,
})
.catch((err) => {
console.error(err.stack);
process.exit(1);
})
.then(async (client) => {
app.listen(port, () => {
console.log(`listening on port ${port}`);
});
});
problem happend here somewhere but for 2 days I cannot figure out why... If anyone has an idea how I can solve this, thanks in advance.