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

195
Vistas
add parameters to node script

I'm trying to add some custom scripts to package.json and I want to pass filepaths as parameters to the scripts for example i have this script

    "captures": "node ./interfaceVisualTesting/captures.js",

which requires json files:

const repjsonref = require('../json/report1.json');

I want my script to be like this

"captures": "node ./interfaceVisualTesting/captures.js ../json/report1.json

and to require the parameter in the javascript file how can i do that ?

EDIT

I realized that i didn't ask the right question what i meant is i want the path to be passed as a parameter while writing the script like this

`npm node-script captures <path of json>`
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could pass the path value as an environment variable

package.json

"captures": "REPORT_PATH='../json/report1.json' node ./interfaceVisualTesting/captures.js",
const repjsonref = require(process.env.REPORT_PATH);
about 4 years ago · Juan Pablo Isaza Denunciar

0

I figured out how to add variables to the node script in this question How do I pass command line arguments to a Node.js program? but all i had to do was add the variables in the script when it was called

npm run-script captures <path1> <path2>

and then add them to the javascript like this

x=require(process.argv[2]);//path1
y=require(process.argv[3]);//path2
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