How to pass file file path as arguement to the script?

Viewed 568

I want to send the data from

package.json:

 "scripts": {
    "start": "node list.js",
}

list.js:

const serviceAccount = require(path);

when I execute command npm start ./style.json I wanted to pass the path to to path variable in list.js

How can I do that?

1 Answers

Basically, you need to use process.argv, the third item is ./style.json. inside list.js use this:

const path = process.argv[2]
const serviceAccount = require(path);
console.log(serviceAccount)
Related