Diary of a React Dev

Sally Mugisha
1 min readOct 24, 2023

--

24th October 2023

Today I learnt that I have been having trouble accessing the code in my .env file because I had not installed dotenv in my react app.

What is dotenv?

Dotenv is a package that is used to load environment variables from the .env file.

Steps Taken to Resolve Issue:

If you haven’t created one already:

  1. Create a .env file at the root of your project.
  2. Define the variable e.g REACT_APP_BASE_URL=http://localhost:7000.

3. npm install dotenv

4. npm start

The react app should now load the environment variables from the variables in the .env file of the react app.

For node.js:

  1. Create a .env file at the root of your project.
  2. Define the variable as follows: e.g BACKEND_API_URL=http://localhost:7000
  3. npm install dotenv
  4. At the beginning of your index file, add the following line: require(‘dotenv’).config();
  5. Restart your server to load your changes.

Remember, your links should be (https://) and not (http://) as used above, for security measures .

Read more here.

The links above are examples of urls used in local development environments.

.env

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sally Mugisha
Sally Mugisha

Written by Sally Mugisha

🌱Chronicling my daily code fumbles so you don't have to...🍀

No responses yet