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 (
jscpdcommand) 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
| Option | Description | Default |
|---|---|---|
-p, --port | Port to run the server on | 3000 |
-H, --host | Host to bind the server to | 0.0.0.0 |
-c, --config | Path to config file | .jscpd.json |
-f, --format | Format or formats (comma-separated) | - |
-i, --ignore | Glob pattern for files to exclude | - |
-l, --min-lines | Minimum lines in a duplication | 5 |
-k, --min-tokens | Minimum tokens in a duplication | 50 |
-m, --mode | Quality mode (strict, mild, weak) | strict |
-a, --absolute | Use absolute paths in reports | false |
-n, --noSymlinks | Don't follow symlinks | false |
--skipLocal | Skip duplicates in local folders | false |
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 checkformat(required, string): Programming language/format (e.g. "javascript", "typescript")recheck(optional, boolean): Iftrue, 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