Skip to content

Instantly share code, notes, and snippets.

@jbsulli
Last active November 25, 2020 05:27
Show Gist options
  • Save jbsulli/37b7b59028e1ae2a67b9b3963410ebdf to your computer and use it in GitHub Desktop.
Save jbsulli/37b7b59028e1ae2a67b9b3963410ebdf to your computer and use it in GitHub Desktop.
How to create a node command line integration module

Node CLI

As recommended by JavaScript Playground.

package.json

add:

{
    "preferGlobal":true,
    "bin":{
        "<cli-command>":"index.js"
    }
}

remove (optional):

{ "main":"index.js" }

index.js

#!/usr/bin/env node
const args = process.argv.slice(2);

add command to path

npm

npm link

yarn

You will need to add the globals to the path:

export PATH="$(yarn global bin):$PATH"

And link:

yarn link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment