How to create your command-line program (CLI) with NodeJS and Commander.js | by Duc N. | JavaScript
$ git clone https://github.com/yourname/json-now.git$ cd json-now{ "name": "json-now", "version": "0.0.1", "bin": { "json-now": "./bin/index.js" }, "dependencies": { "commander": "^3.0.1" }}$ npm install#!/usr/bin/env nodeconst program = require('commander');const ver = require('../lib/ver');program .usage('[options] <file>') .option('-v, --version', 'show version', ver, '') .option('-p, --port <port>', 'use custom port') .option('-f, --flag', 'boolean flag', false) .action((file, options) => { console.log('file name: ', file); // more hanlder: require('../lib/moreHandler')(options); }) .parse(process.argv);const package = require('../package.json')module.exports = () => { console.log(package.version);};$ node bin/index.js -v0.0.1$ node bin/index.js sample.jsonfile name: sample.json$ npm login$ npm publishTry out your shiny new command:$ npm install json-now -g$ json-now -vLast updated