James Pegg
James Pegg

Reputation: 191

Is it possible to run a script on a node.js dependency?

I'm working on a node package which has an installation script to set up a simple application structure. It's not doing anything too strenuous, just creating a few folders and creating an "admin" user if one doesn't exist.

At the moment it's doing a bunch of checks every time the application starts and does the setup process if required. Is there any way of doing it through the command line? Something along the lines of the user just typing my-package install or npm run my-package-install to call the script?

Upvotes: 0

Views: 1366

Answers (1)

Tyler.z.yang
Tyler.z.yang

Reputation: 2450

yes, with npm, you can build a simple commandline tool.

And you can define/parse the args from terminal.

You need to define the script you want to run in your package.json.

"bin": {
    "your-command": "bin/commit.js"
}

And run npm link, this would make the command available.

For more detail, check Building a simple command line to with npm

Hope this can answer your question. : )

Upvotes: 4

Related Questions