Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to run a script with custom values?

My script prints text to the console every second and stops after 4 seconds. I need to make sure that the interval and stop values ​​can be specified when the file is run. The file should be run with this command: node index.js -i 1000 -t 4000. How can i do this?

app.get("/", (req, res) => {
  function outputText() {
    console.log("Some Text");
  }
  const interval = setInterval(outputText, 1000);
  setTimeout(() => {
    clearInterval(interval);
  }, 4000);

  res.send();
});

app.listen(3000);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the npm package yargs

const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers');

const argv = yargs(hideBin(process.argv)).argv;

console.log('Interval', argv.i);
console.log('Stop', argv.t);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading