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

223
Vistas
Setting custom variables from npm script to javascript

Might be a duplicate but is there a way to set variables from an npm script that are accessible in javascript via something like process.env.CUSTOM_VAR?

In my package.json in the scripts section I've added "start": "react-native start --reset-cache" which works fine but now I'd like to do something like this "inspect": "INSPECT=1 react-native start --reset-cache" and have it accessible in javascript. I've googled around everything seems to point to adding it like above but it doesn't seem to be working.

Any help is appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can have a program to read the process.argv and do things based on that list(process.argv includes the flags that the script started on)

argvToEnv.js

//you can set the prefix to your liking
const prefix="*" //the start script may have many flags
//if any flag starts with a prefix, it will turn it into an env variable
let envList={} //soon to be list of things env variables
for(let i=0;i<process.argv.length;i++){
  let flag=process.argv[i]
  if(flag.startsWith(prefix)){
    envList[process.argv[i++].substr(prefix.length)]=process.argv[i]
  }
}
Object.keys(envList).forEach(key=>{
  process.env[key]=envList[key]
})

index.js

require('path/to/argvToEnv.js')
//whatever else you do in your main js file

start script

"start": "react-native start --reset-cache *CUSTOM_VAR \"success hehe\""
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