Basic Node and Express - Use the .env File

If you are using Replit, you cannot create a .env file. Instead, use the built-in SECRETS tab to add the variable.//i don’t know to how to use built -in secrets tab with replit i need your help


It’s here in the Tools.
Just enter MONGO_URI in one field and your URI in the other and click ‘Add new secret’.
Then you can access the variable as process.env.MONGO_URI.

If you are working locally, you will need the dotenv package. It loads environment variables from your .env file into process.env . The dotenv package has already been installed, and is in your project’s package.json file. At the top of your myApp.js file, add require('dotenv').config() to load the environment variables.

//
.replit
(‘dotenv’)
.config()
it will look like this??

Are you using replit? Or are you working on your local files?

i’m using replit but my code is not working

Could you link to your code on replit please? (The url in the address bar when you’re on the repl).

@borel You can use the same replit for all of the challenges within a section unless the instructions say otherwise. Most new curriculum sections start with a new starter boilerplate that you must use for that section.

As far as passing this challenge, your existing code in https://replit.com/@bowak/boilerplate-express-13 will pass as long as you have added the correct environment variable (MESSAGE_STYLE) and value (uppercase) to the Secrets section.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.