Directly call globally installed Node.js modules

我们两清 提交于 2019-12-01 05:29:24

You need to write an executable file. This is what will be executed when a user types your command. Here's an example taken from JSHint:

#!/usr/bin/env node

require("./../src/cli/cli.js").interpret(process.argv);

Convention says to place this file in a bin directory in the root of your project. You then just need to update your package.json file to tell it where to find your executable:

{
    "bin": {
        "jshint": "./bin/jshint"
    }
}

In this case, the executable file can be run from the terminal with the jshint command. When it runs, it simply requires another file and calls a method in it, passing through any command line arguments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!