Skip to content

Instantly share code, notes, and snippets.

@gayanvirajith
Created June 3, 2021 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gayanvirajith/990e1d4cc097a0c071017c2c0ba9c893 to your computer and use it in GitHub Desktop.
Save gayanvirajith/990e1d4cc097a0c071017c2c0ba9c893 to your computer and use it in GitHub Desktop.
Node command line arg sample
const commandLineArgs = require("command-line-args");
const commandArgs = commandLineArgs([
{
name: "check",
type: Boolean
},
{
name: "export",
type: Boolean
}
], { camelCase: true });
(async () => {
try {
if (commandArgs.check) {
// code
} else if (commandArgs.export) {
// code
}
} catch (error) {
console.error(`Exception: ${error.stack}`);
} finally {
// connection close
}
})();
// node index.js --check
// node index.js --export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment