Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

370
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda