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

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

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