From CLI you can get any parameter from it order or parameter name. Node.js version >= 6
npm install cli-parameter-getter
- You can use this:
node index.js 1337
- Implementing this way:
const cliParameters = require('cli-parameter-getter').get()
const portParameter = cliParameters[0]
console.log(portParameter)
// { name: '1337', value: '1337' }
- You can use this:
node index.js port=1337
- Implementing this way:
const cliParameters = require('cli-parameter-getter').get()
const port = cliParameters.port
console.log(port)
// 1337
const portParameter = cliParameters[0]
console.log(portParameter)
// { name: 'port', value: '1337' }
- You can use this:
node index.js port=1337 app-test
- Implementing this way:
const cliParameters = require('cli-parameter-getter').get()
const port = cliParameters.port
console.log(port)
// 1337
const portParameter = cliParameters[0]
console.log(portParameter)
// { name: 'port', value: '1337' }
const nameParameter = cliParameters[1]
console.log(nameParameter)
// { name: 'app-test', value: 'app-test' }
You can test the package:
- Releases
npx release-it