How to pass parameters to a script processed by ts-node

You did not provide your script, so I can only guess at how you are extracting the arguments. This is how I have made it work with my own test script args.ts:

const a = process.argv[2];
const b = process.argv[3];
const c = process.argv[4];
console.log(`a: '${a}', b: '${b}', c: '${c}'`);

Called from package.json like this:

"scripts": {
   "args": "ts-node ./args.ts -- 4 2 printer:A"
}

This will give me output like this:

a: '4', b: '2', c: 'printer:A'

Leave a Comment