node-commandline

Smart command line parser and handler for node js.

Node-commandline

The smart Node JS command line parser module provides an easy API that makes an abstraction of a command line. It allows you to specify the order and type of the expected (required) arguments, and the names and types of the optional (named) arguments.

It uses a json-style notation for command lines, for example:

node example.js -debug -encoding:ascii -value:4.5 some ordered arguments -flag:false

All arguments are parsed, and the resulting object will have the following properties:

  • debug=true
  • enoding="ascii"
  • value=4.5
  • flag=false
  • orderedArgumens=["some","ordered","arguments"]

It is possible to map the ordered arguments to property names by specifying those names at object construction time.

The command line class will after construction expose all argument values as normal JavaScript properties. It can also output the resulting usage syntax, and validate the input. In JavaScript, you can extend objects with properties and functions at run time. node-commandline uses this technique in order to create a model of the command line and it's arguments.

The easiest way to install node-commandline is to use the NPM package manager:

npm install node-commandline

This project is derived from my previous work for the node js serial-to-tcp server.