NPM reads package names from the first slug ion the URL in the request. Artifactory URLs have a bunch of slugs before the package name. This means that when NPM prints out the package name in case of an error, you don’t get the package name when using Artifactory.
This Nginx config will allow you to proxy requests from a naked path on a local Nginx server to the full Artifactory URL.
Create a file in the current directory called nginx.conf
(or any name of your choice, just make sure you use than name in all instructions) and add the following:
events {
worker_connections 1024;
}
http {
server {
listen 8080;
server_name localhost;
location ~ /(?<path>.*) {
proxy_redirect off;
rewrite /(.*) /artifactory/api/npm/npm/$1 break;
proxy_pass https://your-artifactory-host;
}
}
}
Edit the .npmrc
file in your Node project's root (create it if it doesn't exist), and set the registry to the local Nginx server as follows:
registry=http://localhost:8080
$ nginx -c $PWD/nginx.conf
Then run your NPM installs in the usual way. To kill Nginx when you are finished just run nginx -s stop
.
#code #toolbox #node