My Node.js script is running differently between the command line and from within a bash script. Everything works normally via the command line, but the second argument is not being recognized when run from within the bash script.
Do I need to pass the arguments differently inside the bash script?
server.js is provided two arguments:
1. Command (in this case, update a table via mySQL)
2. Table (desired table to update via data pulled from API)
Command Line/Script Entry:
node server.js -update-table table1
server.js:
var args = process.argv.slice(2);
var command = args[0];
switch (command) {
case '-update-table':
var tableName = args[1];
switch (tableName) {
case 'table1':
tableUpdateFunction.table1();
break;
case 'table2':
tableUpdateFunction.table2();
break;
default:
console.log('ERROR: Unknown Table Name ' + tableName)
break;
}
break;
}
Console When Run from Script (Triggers Default Case):
ERROR: Unknown Table Name table1