API

Server API

Use jscpd-server for remote duplication detection.

Installation

Terminal
npm install -g jscpd-server

Note: The jscpd-server is still Node.js based. The CLI detection engine (jscpd command) is Rust-based in v5, but the server uses the v4 engine.

Starting the Server

Terminal
# Start server in current directory
jscpd-server

# Start server in specific directory
jscpd-server /path/to/project

# Start server on specific port
jscpd-server . --port 8080

Server Options

OptionDescriptionDefault
-p, --portPort to run the server on3000
-H, --hostHost to bind the server to0.0.0.0
-c, --configPath to config file.jscpd.json
-f, --formatFormat or formats (comma-separated)-
-i, --ignoreGlob pattern for files to exclude-
-l, --min-linesMinimum lines in a duplication5
-k, --min-tokensMinimum tokens in a duplication50
-m, --modeQuality mode (strict, mild, weak)strict
-a, --absoluteUse absolute paths in reportsfalse
-n, --noSymlinksDon't follow symlinksfalse
--skipLocalSkip duplicates in local foldersfalse

API Endpoints

Check Code Snippet

POST /api/check

Check a code snippet for duplications against the scanned codebase:

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

Parameters:

  • code (required, string): The code snippet to check
  • format (required, string): Programming language/format (e.g. "javascript", "typescript")
  • recheck (optional, boolean): If true, triggers a re-scan before checking

Response:

{
  "duplications": [
    {
      "snippetLocation": {
        "startLine": 1,
        "endLine": 5
      },
      "codebaseLocation": {
        "file": "src/utils/helper.js",
        "startLine": 10,
        "endLine": 14,
        "fragment": "function hello() {\n  console.log(\"Hello, World!\");\n}"
      },
      "linesCount": 4
    }
  ],
  "statistics": {
    "totalDuplications": 1,
    "duplicatedLines": 4,
    "totalLines": 5,
    "percentageDuplicated": 80.0
  }
}

Get Project Statistics

GET /api/stats

Get overall duplication statistics for the scanned codebase:

Terminal
curl http://localhost:3000/api/stats

Health Check

GET /api/health

Check server health and initialization status:

Terminal
curl http://localhost:3000/api/health

Response:

{
  "status": "ready",
  "workingDirectory": "/path/to/project",
  "lastScanTime": "2025-11-17T10:30:00.000Z"
}

API Information

GET /

Get information about available endpoints.

CI/CD Integration

.github/workflows/jscpd.yml
name: Check Code Duplication
on: [push, pull_request]

jobs:
  check-duplication:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install jscpd
        run: npm install -g jscpd
      - name: Check for duplications
        run: jscpd --threshold 5 ./src