0

I am looking to create a locally running Node.js server that can intercept outgoing requests to the NPM registry (npmjs.org, or whatever).

Is that what a reverse proxy is?

Basically what I would like to do is create a locally running NPM registry - this is for use with locally running Docker containers. Normally I would just use npm link for local development. But when testing libraries using Docker locally, using npm link for that becomes hard to impossible

I know there are some libraries out there that set up a local NPM registry, but I am looking to do this from scratch so I can set it up for my use case. Essentially I want to tarball packages that exist on my filesystem each time an npm install request comes in.

I started experimenting with:

npm config set registry http://localhost:3440

but when I subsequently did an npm install, it didn't seem to hit my locally running server, just went to registry.npmjs.org like normal.

I also tried modifying /etc/hosts

before:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

after:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
registry.npmjs.org localhost:3440

but my local server listening on port 3440 did not seem to intercept any traffic.

1 Answers1

0

That's not a reverse proxy, but that's a forward proxy. And you'll effectively have to use npm config set proxy to use it from npm call.

The main tool used for such proxy is usually squid proxy. And I'm pretty sure you can build more robust and feature-full service using some well known forward proxy tools instead of a custom nodejs tool.

Then you'll have to check where this service is running (on the same docker? on another docker? on your host?). The address you set for npm, in npm config set proxy must be resolvable from inside the container running npm (but it may differ between commands running on the Dockerfile step and commands running in a bash session after that build).

regilero
  • 29,806
  • 6
  • 60
  • 99
  • thanks this helps - do you happen to understand this question? https://stackoverflow.com/questions/50341587/create-proxy-server-to-npm-registry – Alexander Mills May 15 '18 at 02:47