Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
How to configure React package.json file to use different .env files for different builds with dotenv

I am using dotenv with create-react-app. I have three different .env files in my root directory. I have .env .env.develop .env.stage

I want the variables in these file to map as described below

.env                   -> production site

.env.develop           -> local development

.env.stage             -> stage site

I am guessing that I have to make some changes to the scripts object in the package.json file but I am not sure of what to exactly do.

My current package.json is as follows

{
  "name": "web_app",
  "version": "0.1.0",
  "private": true,
  "homepage": "",
  "devDependencies": {... },
  "dependencies": {... },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

So I would like to know how to tell react to use the correct .env file for each environment.

Thanks in advance to anyone who can help

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!