Pages

Showing posts with label cli. Show all posts
Showing posts with label cli. 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