简体   繁体   中英

Node.js - Modify node_module content

Here is the deal, I have downloaded a node module. But I had to modify the code of the library.

Now I want to upload my code to heroku , but heroku will install the dependencies of the package.json file, and the code of the library will be unchanged.

So is there a way to put that module outside of the node_modules folder?

The only references of the library is in the package.json file. And in the program, the library is accessed by one file.

var containerVar = require('modified_module');

You can host your modified (local) package on Github and install the package from there.

For example, if I modified redis module, I can upload the modified package on to Github and tell my app to install from Github as opposed to installing from NPM.

The dependency part of my package.json file would look like this

"dependencies": {
    "moment": "^2.22.2",
    "redis-modified": "github:username/redis-modified",
}

You can use it like any regular module

var redis = require("redis-modified");

In summary, you would be creating a new version of the package and hosting it.

Better way would be to write your own module. So, take the module that you need, change its content as you already done and in its package.json give it your new custom name. You can even publish it on npm. You only need to sign up to npm. Than you can call in your projects package.json module that you have published and your problem is solved.

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