Skip to content

How to use with native ECMAScript modules

Lloyd Brookes edited this page Mar 24, 2019 · 1 revision

Install command-line-args.

$ npm install command-line-args

Example script (save it as index.mjs). This example loads the command-line-args ECM distribution.

import commandLineArgs from './node_modules/command-line-args/dist/index.mjs'

const optionDefinitions = [
  { name: 'verbose', type: Boolean }
]
const options = commandLineArgs(optionDefinitions)
console.log(options)

Run the script.

$ node --experimental-modules index.mjs --verbose
{ verbose: true }