# npm

---

## Overview

Your private npm packages and public dependencies from npmjs.org, all managed through one registry.

---

## Supported Clients

JFrog Fly supports npm packages built with:

- **npm CLI** (`npm publish`, `npm install`) - The standard Node.js package manager included with Node.js

- **pnpm** (`pnpm publish`, `pnpm install`) - Fast, disk-space-efficient package manager

---

## Upload / Publish Package

### With Fly App

Activate npm in your Fly App to configure your `.npmrc` globally with Fly, then publish as usual:

```bash
npm publish
```

**Using pnpm:**
```bash
pnpm publish
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure npm** in your project or home directory. Create or edit `.npmrc`:

```ini
registry=https://<your-fly-subdomain>.jfrog.io/artifactory/api/npm/npm/
//<your-fly-subdomain>.jfrog.io/artifactory/api/npm/npm/:_authToken=<your-fly-token>
```

**3. Publish:**

```bash
npm publish
```

**Using pnpm:**
```bash
pnpm publish
```

> [!IMPORTANT]
> You cannot publish a package version that already exists. Increment the version in your `package.json` before publishing again.

---

## Download / Install Package

### With Fly App

Activate npm in your Fly App to configure your `.npmrc` globally with Fly, then install as usual:

```bash
npm install <package-name>
```

**Using pnpm:**
```bash
pnpm install <package-name>
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure npm** in your project or home directory. Create or edit `.npmrc`:

```ini
registry=https://<your-fly-subdomain>.jfrog.io/artifactory/api/npm/npm/
//<your-fly-subdomain>.jfrog.io/artifactory/api/npm/npm/:_authToken=<your-fly-token>
```

**3. Install:**

```bash
npm install <package-name>
```

**Using pnpm:**
```bash
pnpm install <package-name>
```

### From Public Registry

When you install a package that isn't in your Fly Registry, JFrog Fly automatically fetches it from npmjs.org and caches it for future use.

```bash
npm install express
```

**Using pnpm:**
```bash
pnpm install express
```

---

## Publish/Install Packages with CI

To publish and install npm packages with CI, update your GitHub Actions workflow to include the Fly action.

Simply ask your coding agent: **"Configure my workflows with Fly"** and Fly MCP will configure your GitHub Actions workflow yml file, as follows:

**1. Add permissions** (top level, after `on:`):
```yaml
permissions:
  contents: read
  id-token: write
```

**2. Add Fly Action** (after `actions/setup-node`, before npm commands):
```yaml
- uses: jfrog/fly-action@v1              # Setup Fly package managers
```

### GitHub Action Example

```yaml
name: Build and Publish npm Package

on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '18'

      - uses: jfrog/fly-action@v1              # Setup Fly package managers

      - run: npm install                       # Dependencies from Fly registry

      - run: npm run build

      - run: npm publish                       # Publish to Fly registry
```

---

*Back to [Package Managers →](../)*
