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

219
Views
Configuración de variables personalizadas desde el script npm a javascript

Podría ser un duplicado, pero ¿hay alguna forma de establecer variables desde un script npm que sean accesibles en javascript a través de algo como process.env.CUSTOM_VAR ?

En mi paquete.json en la sección de scripts, agregué "start": "react-native start --reset-cache" que funciona bien, pero ahora me gustaría hacer algo como esto "inspect": "INSPECT=1 react-native start --reset-cache" y tenerlo accesible en javascript. Busqué en Google, todo parece apuntar a agregarlo como arriba, pero no parece estar funcionando.

¡Cualquier ayuda es apreciada!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede tener un programa para leer el process.argv y hacer cosas basadas en esa lista (el proceso.argv incluye las banderas en las que comenzó el script)

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] })

índice.js

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

guión de inicio

 "start": "react-native start --reset-cache *CUSTOM_VAR \"success hehe\""
about 4 years ago · Juan Pablo Isaza Report
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!