Step 14
We have removed the MongoDB cluster URI from our source code. So what if we want to run our app locally?!
Well, we can create an environment variable DB_URI in our local machine. The process of creating environment variables varies in different environments (e.g., Mac vs. Windows). There is a Node package that makes this as easy as defining variables in a text file.
Install the dotenv package:
npm install dotenv
Create a .env file at the root of this repository. Open the file and add the following:
DB_URI="mongodb+srv://quicknote-admin:<password>@quicknote.ydsfc.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
Make sure to replace
<password>with the admin's password!- add
.envto your.gitignoreso you don't push it to the repository!
Add the following to the top of server/data/db.js
require("dotenv").config();
Save all changes and run the server locally!