Local NPM repository in 5 minutes with its packages and caching
Sooner or later, organizations have problems with the proliferation of js modules between projects, the time has come when this question has arisen in our company.
Copy and paste the code is the way to the dark side, so it was decided to write not just js code, but create from it npm packages to distribute between their projects.
The search for free, private npm repositories led to a dead end, and the use of private repositories on 3r3166. npm
requires a fee (and this is not our mentality).
Since the office has a server that always works (almost), it was decided to deploy the local npm.
Verdaccio , due to the fact that updates for it were published relatively recently.
This is basically the npm package, which is placed on Node.js> 4 and provides a web interface on a specific port.
A huge advantage is the caching function, when the local npm does not find the package requested from it, it goes to npmjs.com, downloads the right package to its disk, and when it re-requests the package, it distributes its already cached version.
So, to customize.
On the machine that will be the server:
3r3208. npm i -g verdaccio
In the file C: UserslabAppDataRoamingverdaccioconfig.yaml are the parameters of the server
The default parameters are viable, nothing can be changed, it is enough to add a setting at the end of the file, thanks to which Verdaccio will understand which port to listen on.
3r3208. listen: ???.79:1234
???.79 is the ip of the server, setting the address so we can access from the local network by ip of the server, or by its DNS name and adding port 1234 we will get to the web interface.
If you register listen: ???.79:80 it is not necessary to write a port when setting up clients.
Next, run our local npm
The remaining actions will be carried out on clients.
Set the path to the local repository.
3r3208. npm set registry http://???.79:1234
Done, now all your npm requests will go and be cached through a local server.
If you need to publish the npm package to the server, then we execute the following instruction.
3r3208. npm adduser - registration http://???.79:1234
3r3208. npm login
We check that we are under the user “login”
3r3208. npm whoami
We publish the package, rootProjectFolder is a folder with at least three files index.js package.json README.md, The example posted on github .
3r3208. cd /rootProjectFolder
Update the package. We update the version in package.json, we execute commands
3r3208. cd /rootProjectFolder
Package on the local server, you can go to 3r3181. ???.79
: 1234 and see what appeared in the new package.
By the way, information about each of the packages is presented in a convenient form and there is a search by local packages.
P.S .: If you have your network with a proxy, then you need to explicitly specify its parameters on the server, and you don’t need to do this on the client, because the npm repository is local and the proxy is not required for clients to access the server.
On the server, run the command npm config edit and add the following lines
3r3208. proxy = http: //name: pass @ proxy: port /
https-proxy = http: //name: pass @ proxy: port /
registry = http: //registry.npmjs.org/
I would welcome comments and feedback on how it works for you.
It may be interesting
Thankyou for sharing the data which is beneficial for me and others likewise to see.Gulf Coast Western Reviews