Get Node.js Command Line Arguments with yargs
Using command line arguments within Node.js apps is par for the course, especially when you're like me and you use JavaScript to code tasks (instead of bash scripts). Node.js provides process.argv
but that doesn't provide a key: value
object like you'd expect:
/*
$ node myscript.js --key1=value1 --key2=value2
[ 'node',
'/path/to/myscript.js',
'--key1=value1',
'--key2=value2' ]
*/
Bleh. If you want to work with a sane API for command line arguments, use yargs:
// Get the yargs resource
var yargs = require('yargs').argv;
// Check for arguments
if(yargs.someKey === expectedValue) {
// Do whatever
}
/*
yargs = {
key1: value1
key2: value2
};
*/
yargs provides a key:value
object for arguments instead of the native process.argv
mess. No hassle, no fuss, just access to command line arguments with a logical API. Happy noding!
![Create a Sheen Logo Effect with CSS]()
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
![CSS Gradients]()
With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements. CSS gradients are another step in that direction. Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...
![CSS Ellipsis Beginning of String]()
I was incredibly happy when CSS text-overflow: ellipsis
(married with fixed width
and overflow: hidden
was introduced to the CSS spec and browsers; the feature allowed us to stop trying to marry JavaScript width calculation with string width calculation and truncation. CSS ellipsis was also very friendly to...
![MooTools Flashlight Effect]()
Another reason that I love Twitter so much is that I'm able to check out what fellow developers think is interesting. Chris Coyier posted about a flashlight effect he found built with jQuery. While I agree with Chris that it's a little corny, it...
[pirateAccent]Yaaaarrrrrg!![/pirateAccent]