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

192
Views
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 answers
Answer question

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 Report

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 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!