node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »



Command line arguments parser for node.js


Let's say you have a script args.js, and call it with

    node args.js -u --name bob


    node args.js --url --name bill

And want to simply print the given url and name. Your script should use arguably like this:

    var arguably = require('arguably'),
        args     = arguably
                            '-n, --name',
                            /* description */ 'Your name',
                            /* default value */ 'unknown'
                        .option('-u, --url')
                        .done() //don't forget to call this at the end
    console.log( === args.n
    args.url === args.u

Notice that the args variable returned by arguably is an object with key/value pairs, as specified in the option description. On options with multiple aliases. like the url (-u or --url), the args has the save value for both of the aliases

    args.u === args.url