Created
June 3, 2021 05:42
-
-
Save gayanvirajith/990e1d4cc097a0c071017c2c0ba9c893 to your computer and use it in GitHub Desktop.
Node command line arg sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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