Pages

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

[NodeJS] Command line tool

Basics

With NodeJS, it's fairly simple to create a command-line tool. First, you need to add bin field into package.json file.


# File: package.json
"bin": {
    "command1": "path/to/command1/implementation",
    "command2": "path/to/command2/implementation",
    "command3": "path/to/command3/implementation"
}

You can have as many commands as you want. I like to store all the executable files in bin/ directory. Let say I want to create a command named node-greet to simply print out a greeting message. Here's the bin field of my package.json

Update bash shell for Mac OS X

Apple releases software update quite often but, unfortunately, bash shell is never updated. The version of bash shell that comes with Max OS is quite old and lacks many features such as globing, exclude-dir when grepping, etc. If you need these features, you will need to update bash shell. First, check the version of your bash.


$ echo $BASH_VERSION
3.2.53(1)-release

$ which bash
/bin/bash