# Installation

> Get started with jscpd.

## v5 (Rust) — Recommended

jscpd v5 is a self-contained native binary — no Node.js runtime required. Install via curl, npm, or cargo.

### Using curl (fastest)

One command installs the `cpd` binary for your platform:

```bash [Terminal]
curl -fsSL https://jscpd.dev/install.sh | bash
```

Install to a custom directory:

```bash [Terminal]
curl -fsSL https://jscpd.dev/install.sh | bash -s -- --prefix ~/.local/bin
```

Install a specific version:

```bash [Terminal]
curl -fsSL https://jscpd.dev/install.sh | bash -s -- --version 5.0.7
```

The script downloads from GitHub Releases (primary) and falls back to the npm registry. It supports macOS (arm64/x64), Linux (x64 glibc/musl, arm64 glibc), and Windows (x64 MSVC via Git Bash/WSL).

### Using npm

The npm package installs a native binary for your platform:

```bash [Terminal]
npm install -g jscpd@5
```

### Using cargo

If you have Rust installed, install directly from crates.io:

```bash [Terminal]
cargo install jscpd
```

This installs both the `jscpd` and `cpd` commands.

### Using Homebrew

If you use Homebrew on macOS or Linux:

```bash [Terminal]
brew install jscpd
```

### Using Nix

Install with [Nix](https://nixos.org) (installs both `jscpd` and `cpd` commands):

```bash [Terminal]
nix profile install github:kucherenko/jscpd
```

Or run without installing:

```bash [Terminal]
nix run github:kucherenko/jscpd -- /path/to/source
```

### Using npx (No Installation)

Run jscpd directly without installing (downloads the native binary on first run):

```bash [Terminal]
npx jscpd@5 /path/to/source
```

### Using yarn

```bash [Terminal]
yarn global add jscpd@5
```

### Using pnpm

```bash [Terminal]
pnpm add -g jscpd@5
```

### Platform Binaries

Direct downloads are available for each platform:

<table>
<thead>
  <tr>
    <th>
      Platform
    </th>
    
    <th>
      Package
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      macOS Apple Silicon
    </td>
    
    <td>
      <code>
        cpd-darwin-arm64
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      macOS Intel
    </td>
    
    <td>
      <code>
        cpd-darwin-x64
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Linux x64 (glibc)
    </td>
    
    <td>
      <code>
        cpd-linux-x64-gnu
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Linux ARM64 (glibc)
    </td>
    
    <td>
      <code>
        cpd-linux-arm64-gnu
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Linux x64 (musl/Alpine)
    </td>
    
    <td>
      <code>
        cpd-linux-x64-musl
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Windows x64
    </td>
    
    <td>
      <code>
        cpd-windows-x64-msvc
      </code>
    </td>
  </tr>
</tbody>
</table>

---

## v4 (TypeScript) — Maintenance

If you need the Node.js programmatic API, install v4:

```bash [Terminal]
npm install -g jscpd@4
```

```bash [Terminal]
# Or run without installing
npx jscpd@4 /path/to/source
```

v4 requires Node.js 18+ and provides the `import { jscpd } from 'jscpd'` API. See the [Migration Guide](/getting-started/migration) for details on coexistence.

---

## Basic Usage

<steps>

### Scan a directory

Run jscpd on your source code directory (same command in v4 and v5):

```bash [Terminal]
jscpd /path/to/source
```

### Use pattern matching

Scan specific file patterns:

```bash [Terminal]
jscpd --pattern "src/**/*.js"
```

### Generate HTML report

Create an HTML report of duplications:

```bash [Terminal]
jscpd /path/to/source --reporters html
```

</steps>

## Configuration

Create a `.jscpd.json` file in your project root (compatible with both v4 and v5):

```json [.jscpd.json]
{
  "threshold": 0,
  "reporters": ["html", "console"],
  "ignore": ["**/__snapshots__/**", "**/node_modules/**"],
  "absolute": true
}
```

## Rust Crate API (v5 only)

jscpd v5 provides Rust crates for programmatic integration:

```toml [Cargo.toml]
[dependencies]
cpd-finder = "0.1"
```

```rust [src/main.rs]
use cpd_finder::orchestrate;

fn main() {
    let result = orchestrate(&["./src".into()], &Default::default());
    println!("Found {} clones", result.statistics.total_clones);
}
```

## Node.js API (v4 only)

If you need the programmatic JavaScript API:

```typescript
import { IClone } from '@jscpd/core';
import { jscpd } from 'jscpd';

const clones: IClone[] = await jscpd(['', '', './src', '-r', 'json']);
console.log(clones);
```

> **Note:** This API is only available in `jscpd@4`. See the [Migration Guide](/getting-started/migration) for alternatives in v5.

## JSCPD Server

The server component (REST API + MCP) is still Node.js based and works with both versions. Install and run:

```bash [Terminal]
npm install -g jscpd-server
jscpd-server
```

Then check code for duplication:

```bash [Terminal]
curl -X POST http://localhost:3000/api/check \
  -H "Content-Type: application/json" \
  -d '{
    "code": "console.log(\"hello\");\nconsole.log(\"world\");",
    "format": "javascript"
  }'
```
