1

I am learning to build an MEVN project. I have a MongoDB connection string that looks like this "mongodb+srv://<username>:<password>@<clustername>.abcdefg.mongodb.net/?retryWrites=true&w=majority". During development, I directly embed the connection string in my server.js for convenience.

I'm considering deploying it on somewhere, so I am finding where I should store my connection string in.

Question 1: I tried to put the connection string in .env.local like MONGODB_URI="mongodb+srv://<username>:<password>@<clustername>.abcdefg.mongodb.net/?retryWrites=true&w=majority" in the project root directory, but logging MONGODB_URI always shows undefined. Does the file location matter, say only the files in the root directory can access .env.local? My Vue version is 2.6.11.

Question 2: I read from somewhere that says "don't put your connection string in your Vue project". Does this statement cover all environment variables, including those in .env and .env.local? How should I set up my connection string to avoid hardcoding in my .js file?

1
  • This question is similar to: How to store secret keys in VueJs. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Sep 17 at 18:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.