API & Developer
Tools
The same 55-language comment removal engine, available as a REST API, npm package, and CLI. Zero dependencies. Works everywhere.
The engine ships as the open-source uncommenter package on npm and powers the same browser tool you can use directly. The parser is character-driven so it understands the difference between a comment and comment-like syntax inside template literals, regex literals, and Python docstrings.
For deeper context on the design and trade-offs, see the about page or browse the engineering blog.
REST API
Three endpoints. JSON in, JSON out. No API key required.
/api/v1/uncommentRemove comments from source code. Supports all 55 languages with auto-detection.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| code | string | Yes | — | Source code to process |
| language | string | No | — | Language ID (e.g. "python"). Omit for auto-detection. |
| filename | string | No | — | Filename for extension-based detection |
| options.preserveDocstrings | boolean | No | true | Keep docstrings (Python, Elixir) |
| options.preserveShebangs | boolean | No | true | Keep shebang lines (#!/...) |
| options.preserveTodos | boolean | No | false | Keep TODO/FIXME comments |
Request
{"code": "def hello():\n # comment\n print('hi')","language": "python","options": {"preserveDocstrings": true,"preserveTodos": false}}
Response
{"processed": "def hello():\n print('hi')\n","language": "Python","commentsRemoved": 1,"linesRemoved": 1}
/api/v1/detectDetect the programming language of source code using extension, shebang, and content analysis.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| code | string | Yes | — | Source code to analyze |
| filename | string | No | — | Filename for extension-based detection |
Request
{"code": "def hello():\n print('hi')","filename": "app.py"}
Response
{"language": "python","name": "Python","confidence": "high","extensions": [".py", ".pyw", ".pyi"]}
/api/v1/languagesList all 55 supported languages with their comment syntax and features. Cached for 24 hours.
Response
{"count": 55,"languages": [{"id": "javascript","name": "JavaScript","extensions": [".js", ".jsx", ".mjs", ".cjs"],"lineComment": ["//"],"blockComment": [{ "start": "/*", "end": "*/" }],"features": {"hasRegexLiterals": true,"shebangs": false,"docstrings": false,"nestedBlockComments": false,"rawStrings": false}}]}
Try It
Test the API right here. Paste code, pick a language, hit Run.
Try it live
Code Examples
Call the API from any language.
curl -X POST https://uncommenter.com/api/v1/uncomment \-H "Content-Type: application/json" \-d '{"code": "const x = 1; // comment\nlet y = 2; /* block */","language": "javascript"}'
npm Package
Import the engine directly. Zero runtime dependencies. CJS + ESM + full TypeScript definitions.
$ npm install uncommenterQuick Start
import { uncomment } from "uncommenter";const result = uncomment('const x = 1; // this is a comment','javascript');console.log(result.processed); // "const x = 1;\n"console.log(result.commentsRemoved); // 1console.log(result.language); // "JavaScript"
Auto-Detection
import { uncomment, detectLanguage } from "uncommenter";// Detect by filename extensionconst result = uncomment(code, undefined, "app.py");// Detect by content analysisconst lang = detectLanguage(code);console.log(lang.name); // "Python"
Low-Level Parser
import { removeComments, languageMap, DEFAULT_OPTIONS } from "uncommenter";const config = languageMap.get("python")!;const { result, commentsRemoved } = removeComments(source,config,{ ...DEFAULT_OPTIONS, preserveTodos: true });
Exports
// Functionsexport { uncomment } from "uncommenter";export { removeComments } from "uncommenter";export { detectLanguage, detectByExtension, detectByShebang, detectByContent } from "uncommenter";// Dataexport { languages, languageMap, extensionMap } from "uncommenter";// Typesexport type { LanguageConfig, UncommentOptions, UncommentResult } from "uncommenter";export { ParserState, DEFAULT_OPTIONS } from "uncommenter";
CLI
Strip comments from files and directories right from your terminal.
$ npm install -g uncommenterCommands
# Process a single file in-placeuncommenter src/app.ts# Write to output fileuncommenter src/app.ts -o clean/app.ts# Recursive directory processinguncommenter src/ -r# Pipe mode (stdin to stdout)cat main.py | uncommenter --stdin -l python# Show colored diff (no changes written)uncommenter src/app.ts --diff# Preview what would changeuncommenter src/ -r --dry-run# List all 55 supported languagesuncommenter languages
Flags
| Flag | Description |
|---|---|
| -r, --recursive | Process directories recursively |
| -l, --language <lang> | Force language (skip auto-detection) |
| -o, --output <path> | Write output to file |
| -d, --diff | Show colored diff |
| --dry-run | Preview changes without writing |
| --stdin | Read from stdin, write to stdout |
| -g, --glob <pattern> | Filter files by extension |
| --exclude <dirs> | Comma-separated dirs to exclude |
| --preserve-docstrings | Keep docstrings (default: true) |
| --no-preserve-docstrings | Remove docstrings |
| --preserve-todos | Keep TODO/FIXME comments |
| --preserve-shebangs | Keep shebangs (default: true) |
| --no-preserve-shebangs | Remove shebangs |
Config File
Create a .uncommenterrc file in your project root:
{"preserveDocstrings": true,"preserveShebangs": true,"preserveTodos": false,"exclude": ["node_modules", "dist", ".git", "vendor"]}
Real-World Examples
# Clean up a TypeScript project before shippinguncommenter src/ -r -g "*.ts" --no-preserve-docstrings# Preview changes to Python files, keeping TODOsuncommenter lib/ -r -g "*.py" --preserve-todos --diff# Process a single file, output to new locationuncommenter legacy/app.js -o clean/app.js# Pipe through in a shell scriptcat input.sql | uncommenter --stdin -l sql > clean.sql# Clean everything except testsuncommenter src/ -r --exclude "tests,__mocks__"
Errors & Limits
Error Responses
| Code | Error | Description |
|---|---|---|
| 400 | Bad request | Missing or invalid "code" field, or unknown language |
| 413 | Payload too large | Code exceeds 1MB limit |
| 429 | Too many requests | Rate limit exceeded (100 req/min) |
| 500 | Internal server error | Processing failed unexpectedly |
Rate Limiting
The API is rate-limited to 100 requests per minute per IP. Rate limit headers are included in every response:
X-RateLimit-Limit: 100X-RateLimit-Remaining: 97X-RateLimit-Reset: 1706745600
When the limit is exceeded, you'll receive a 429 response with a Retry-After header indicating when you can retry.
Limits
| Limit | Value |
|---|---|
| Max request body | 1 MB |
| Rate limit | 100 requests / minute |
| Languages supported | 55 |
| API key required | No |
| CORS | All origins allowed |