Page Contents

Overview

Bintray is a fully-fledged npm repository and works seamlessly with the npm client with which you can resolve packages from or deploy them to Bintray directly.

Tip
To get code snippets formulated for your specific username and repository, use the Set Me Up button.

Configuring the npm Client

To configure the npm client to work with Bintray you need to provide it with some details for authentication which you can obtain with the following command:

 curl -u<USERNAME>:<API_KEY> https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/auth

The response from this call should be pasted into your ~/.npmrc file (in Windows, %USERPROFILE%/.npmrc). The contents to paste should contain the following fields:

 registry=https://api.bintray.com/npm/<USERNAME>/<REPOSITORY
 _auth=<USERNAME>:<API_KEY> (converted to base 64)
 email=<EMAIL>
 always-auth=true

To replace the default npm registry with your Bintray repository, run the following command:

 npm config set registry https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>

Using Scoped Packages

You may also use Bintray to distribute scoped packages. To obtain authentication details for scoped packages use the following command:

 curl -u<USERNAME>:<API_KEY> https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/auth/scope/<SCOPE>

The response from this call should be pasted into your ~/.npmrc file (in Windows, %USERPROFILE%/.npmrc). The contents to past should contain the following fields:

 @<SCOPE>:registry=https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/
 /api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/:_authToken=<BASE64_PASSWORD>
 /api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/:username=<USERNAME>
 /api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/:email=<EMAIL>
 /api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>/:always-auth=true

To replace the default npm registry with your Bintray repository for scoped packages, run the following command:

 npm config set @<SCOPE>:registry https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>

Downloading Files

To download files using Bintray’s REST API, please refer to Downloading Using APIs.

Resolving npm Packages

Once you have configured the npm client and set Bintray as its default repository, you can install packages as follows:

 npm install <PACKAGE_NAME>

You an also specify a particular Bintray repository as follows:

 npm install <PACKAGE_NAME> --registry https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>

Uploading Files

Distributing files via Bintray includes three steps: creating a version, uploading the files and publishing the files as follows:

  1. Creating a Version: Uploaded files are associated with a specific version of a package. In some cases, the upload process creates the version automatically; in other cases you need to create a target version through the Bintray UI or using the REST API.

  2. Uploading: You can upload (or deploy) your files using cURL as described below. After uploading your files, the files have a status of "un-published". This means that in the Bintray UI, they are only visible to you and can only be downloaded with your username and API Key. While your uploaded files are still "un-published", you can still discard them before anyone sees or downloads them. The Bintray UI indicates files that are un-published and provides links to publish or discard them.

  3. Publishing: Once you are ready to expose your uploaded files, you can publish them and make them visible and available to all Bintray users. Files can be published via the Bintray UI, or via the REST API, both as part of the upload, or separately. In some cases, uploading the files publishes them automatically, so you can skip this step.

Deploying with the npm Client

To deploy packages to your Bintray npm repository you can either set it in the package.json file as follows:

 "publishConfig":{"registry":https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>}

and then use:

 npm publish

or you can provide the repository each time to the npm publish command:

 npm publish --registry https://api.bintray.com/npm/<USERNAME>/<REPOSITORY_NAME>

Deploying with cURL

The cURL command to upload npm packages is as follows:

 curl -T <FILE.TGZ> -<USERNAME>:<API_KEY> https://api.bintray.com/content/<USERNAME>/<REPOSITORY_NAME>/<YOUR_COOL_PACKAGE_NAME>/<VERSION_NAME>/<FILE_TARGET_PATH>

Once your npm package is uploaded, Bintray automatically calculates the repository-wide npm metadata.