创建shell可执行全局节点模块 [英] Create shell executable Global node module

查看:47
本文介绍了创建shell可执行全局节点模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建节点模块,我成功了,我在代码目录中使用了 npm install -g,它在 \AppData\Roaming\npm\node_modules\myfirstmodule 中创建了这个模块文件夹,现在我想让一个文件可执行作为命令,如 pm2.我怎样才能做到这一点?所以我可以在任何位置的命令提示符中键入 myfirstmodule ,它就会从该模块执行 index.js.

I tried to create node module, I succeeded, I used npm install -g at code directory, and it created this module folder in \AppData\Roaming\npm\node_modules\myfirstmodule, Now I want to make one file executable as command, like pm2. How can I do this? so I can type myfirstmodule in command prompt at any location and it will execute index.js from that module.

推荐答案

你的 package.json 可以提供一个名为 bin 这将使命令可用.有关详细信息,请参阅本教程.

Your package.json can provide a map called bin which will make commands available. See this tutorial for more details.

这篇关于创建shell可执行全局节点模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆