简体   繁体   English

如何使用定制的节点模块?

[英]How do I use customized node modules?

I've customized an existing node module and would like for my node.js app to use it in production. 我已经定制了一个现有的节点模块,并希望我的node.js应用程序在生产中使用它。

Where should I host the forked version of the module? 我应该在哪里托管该模块的分支版本?

How do I specify that I would like to use the customized module in my package.json ? 如何在我的package.json指定要使用自定义模块?

My production server needs to be able to access the same version I have modified locally in the node_modules/ directory. 我的生产服务器需要能够访问我在node_modules/目录中本地修改的相同版本。

SN: I've tried using Github and pointing to the repo in package.json . SN:我已经尝试过使用Github并指向package.json中的package.json I ran into several issues before taking a step back and wondering if I was taking the best approach. 在退后一步并想知道我是否采用最佳方法之前,我遇到了几个问题。

package.json from Github attempt: 来自Github的package.json尝试:

 ...

  "dependencies": {
    "express": "3.1.x",
    "crawlme": "git@github.com:DruRly/Crawlme.git"
  },

 ...

Well you can host them @ the npm repository itself. 好吧,您可以在npm存储库本身中托管它们。 In fact, anyone can and the best thing about it, is that you can just download your own package through npm install <your package name> . 实际上,任何人都可以而且最好的是,您可以通过npm install <your package name>下载自己的软件包。

To get started, you need to do this like so: 首先,您需要这样做:

  1. Go to your package directory, I see you've already made a package.json file there, so thats good, but its a part of the process. 转到您的包目录,我看到您已经在其中创建了一个package.json文件,这样很好,但这是过程的一部分。 Since you've already made it, I won't elaborate 既然你已经做到了,我就不再赘述
  2. Run this command npm init 运行此命令npm init
  3. Fill out the data it wants. 填写所需的数据。 One interesting part is the point of entry parameter, make sure you think about it before you put something down. 一个有趣的部分是point of entry参数,请确保在放下东西之前先考虑一下。
  4. After that, make sure that you have a npm username, if not run npm adduser and go through the process 之后,请确保您拥有一个npm用户名,如果没有,请运行npm adduser并完成该过程
  5. Then you simply npm publish 然后您只需npm publish

You should not be able to search for your module using the module you named it. 您应该无法使用您为其命名的模块来搜索模块。 npm has also other functionality, for example when you are making it, you can make a git-hub repo link for where your code is posted. npm还具有其他功能,例如在制作时,可以为发布代码的位置创建一个git-hub repo链接。

Now on your host, simply run npm install <your package name> and viola, you can use those packages yourself. 现在,在主机上,只需运行npm install <your package name>和viola,您就可以自己使用这些软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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