whats-the-weather
v1.0.7
Published
A simple node CLI example
Downloads
6
Readme
Creating a command line utility
Creating a node CLI utility is really easy, If you have a basic knowledge of javascript and node you will already know how to write one.
- To get started create a new folder and run
npm init
. Fill out the options. - Open the newly created package.json and add the following:
"bin": {
"<name of package>": "./index.js"
}
- Make sure you replace
<name of package>
with the name of your package. - Create an
index.js
file and add#!/usr/bin/env node
on the first line. - To install the CLI utility run
npm install -g
. This will allow you to run your CLI globally. - You can also run
npm link
, This will bind your local package to the global install so you don't have to reinstall your utility every time you make a change. Runnpm unlink
to remove the link again. - When you are happy with your package you can publish it to http://npmjs.com by running
npm publish
. Every time you wish to make a change you will need to increase the version number inpackage.json
.
You can now start creating your CLI Utility. Browse the files in this package to find out how everything works.
Helpful links
scripting-with-node - A fantastic article for getting started.