ARTIFACTORY: How to download node-pre-gyp pre-compiled binaries from Artifactory?

AuthorFullName__c
Valeriy Petrov
articleNumber
000005212
FirstPublishedDate
2022-02-08T08:22:45Z
lastModifiedDate
2025-05-15

ARTIFACTORY: How to download node-pre-gyp pre-compiled binaries from Artifactory?

For NPM packages that are either Node modules or contain Node modules, we use Artifactory repositories as the single source of truth. Some node modules use node-pre-gyp to download pre-compiled binaries. By default, node-pre-gyp will try to download those binaries from an external resource, like github. This tutorial will leverage the functionality of node-pre-gyp to download binaries from a mirror. In this case, the mirror will be a JFrog Artifactory instance.



For example, there are two ways to download binary files from Artifactory using the npm config arguments:

Add to .npmrc:
{module_name}_binary_host_mirror=http://artifactory.local:8081/{repo-name}/
Or run with $npm install:
$ npm install canvas --canvas_prebuilt_binary_host_mirror=http://artifactory.local:8081/{repo-name}/

This article explains how to make node-pre-gyp download the canvas prebuilt binary from Artifactory -

1. First, create local and remote NPM repositories aggregated by a virtual using the Quick Setup feature.

User-added image

User-added image

2. Replace the default npm registry with a newly created virtual npm repository, test-npm in this example, by running the following command:
$npm config set registry http://artifactory.local:8081/artifactory/api/npm/test-npm/
3. Authenticate the npm client against Artifactory, with the $npm login command.
$npm login
When prompted, enter Artifactory login information.

4. When using the
$npm install canvas command to install the node-canvas package, node-pre-gyp will attempt to download pre-built binaries from https://github.com/.
If you do not have access to github, for example, because you are behind a firewall, or if you simply want to fetch the binaries from Artifactory, follow the steps below.


If you don't have access to github.com, you can get an error message like this:
npm ERR! node-pre-gyp info check checked for "/Users/valeriyp/node_modules/canvas/build/Release/canvas.node" (not found)
npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.9.0/canvas-v2.9.0-node-v102-darwin-unknown-x64.tar.gz
npm ERR! node-pre-gyp ERR! install request to https://github.com/Automattic/node-canvas/releases/download/v2.9.0/canvas-v2.9.0-node-v102-darwin-unknown-x64.tar.gz failed, reason: read ECONNRESET
5. Create a generic remote repository, say node-canvas-remote, that will point to github with the following URL: https://github.com/Automattic/node-canvas/releases/download/

*This is only a base url. Don’t attempt to "test" it, sending a GET request to this endpoint will result in a 404 not found error.

**This article uses node-canvas as an example. We may need to setup additional remote repos in Artifactory for other node modules (repo per module).

User-added image

6. Add the canvas_binary_host_mirror argument to .npmrc file:
$npm config set canvas_binary_host_mirror=
http://<username>:<API_KEY/password>@artifactory.local:8081/artifactory/node-canvas-remote



7.Run $npm install canvas, which should now work, and canvas-v2.9.0-node-v102-darwin-unknown-x64.tar.gz will be downloaded from Artifactory.

Or use the --canvas_binary_host_mirror= in the $npm install command:
$npm install canvas --canvas_binary_host_mirror=http://<username>:<API_KEY/password>@artifactory.local:8081/artifactory/node-canvas-remote


In some cases, for example, when using self-signed certificates to enable TLS encryption between your clients and the Artifactory server, node-pre-gyp may encounter a TLS certificate issue. The error message may look like this:

Error: self signed certificate in certificate chain

Node-gyp does not appear to use the npm certificates settings. Please set or add the following environmental variables to your .npmrc to explicitly point node-gyp to your CA cert:

Set a certificate file (recommended)

set NODE_EXTRA_CA_CERTS=/path/to/your/cert.pem
 

To bypassing TLS verification (risky!)

set NODE_TLS_REJECT_UNAUTHORIZED=0