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

164
Vistas
How to store proccess.argv in .js file for later usage

I have config file

module.exports = {
  foo: proccess.argv[2]
}

how can i pass proccess.argv value to this config file to use it later. Im calling it from npm scrips. So far i tried to call via node - node config.js 'bar'. But i guess its obvoius that arg appears only in runtime. So success scenario would be - call config file via node with passed param - call it later from npm script with stored argv value

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

0

You could write the config-object as a json-string to a file and read that file at some later point and parse its content in order to get back an object. Something like (still needs some error-handling of course):

// config.js
const fs = require('fs');

(() => {
    fs.writeFileSync('./config.json', JSON.stringify({
        foo: process.argv[2]
    }));
})();

Call it with node config.js 'bar' and then at some later point you can use it like this in a different script:

// some-other-script.js
const fs = require('fs');

(() => {
    const config = JSON.parse(fs.readFileSync('./config.json'));
    console.log(config); // will log "{ foo: 'bar' }" to the console
})();
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