-
Start off by first making a node project that can be operated from cli. You can get the cli arguments from
process.argvwhich is an array containing all the command line arguments passed in. -
Put
#! /usr/bin/env nodeon top of your index file(entry point for your project). This is called shabang and let's the OS know what to run the file with. -
Add the following to your package.json
"bin": { "hello": "./index.js" },
This will add tell npm to add the command named
hellowhich will run theindex.jsfile. -
Now running
npm i -gwill install your project as a CLI application. -
Test it.
-
Test it.
-
Test it.
-
To just run
npm publishafter going throughnpm adduser. In order to keep the install size smol you can add"files": ["lib/**/*"],to your package.json so that npm publishes on the files isnide thelibfolder. One other way would be to use.npmignorefile which works just like.gitignore. -
Now anyone can install the cli app by running `npm i -g your_project_name".
this gist is brought to you by my procrastination and my goldfish brain