James Pegg James Pegg - 2 years ago 77
Javascript Question

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
npm run my-package-install
to call the script?

Answer Source

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. : )

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download