简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM