I am using nodejs when using destructuring assignment on array process.argv
I get error Cannot read property 'next' of undefined
.
How to fix this issue? Why is that? Notes: I am using node v6.9.1
let fileIn, fileOut;
let getNodeArguments = () => {
// this is ok
process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`);
});
// this is ok
var hasFileInOutArgs = process.argv.length === 4;
if (!hasFileInOutArgs) {
throw ('arguments for file-in and file-out must be provided');
}
// issue
var [, , argUrlIn, argUrlOut] = process.argv; // error exception here <<<
fileIn = argUrlIn;
fileOut = argUrlOut;
};
getNodeArguments();
More infos: