Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
How to update environment variable dynamically before npm start in React (variable for IP address)

Actually, I am trying to set the REACT_APP_DEPLOY_DOMAIN variable automatically in .env file.

below is one method I tried to achieve the solution to this issue.

below is my script file in which I am getting my IP address

const os = require("os");

const networkInterfaces = os.networkInterfaces();
const ip = networkInterfaces["Wi-Fi"][1]["address"];

REACT_APP_DEPLOY_DOMAIN = `http://${ip}`;
console.log(`http://${ip}`);
return `http://${ip}`;

below is the env variable in .env file

REACT_APP_DEPLOY_DOMAIN =  http://192.168.1.114

And also I tried to update it from the start command but it is setting it as the exact command

    "start": "set REACT_APP_DEPLOY_DOMAIN=node ./src/components/getIp.js && react-scripts start",

And also my script file is not running when I try to run the below command.

"start": "node ./src/components/getIp.js && react-scripts start",
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Update the start command to this, it works on Linux/Mac. Hopefully, it'll also work on windows

"start": "set REACT_APP_DEPLOY_DOMAIN=$(node ./src/components/getIp.js) && react-scripts start",
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda