| name | nodejs-documentation-standards |
| description | Reference knowledge base for the nodejs-doc-comments agent. Loaded by that agent on its first iteration when the host has not already injected it; not intended for direct invocation. |
Node.js / TypeScript Documentation Standards
A comprehensive guide to JSDoc documentation comments following the JSDoc
specification and TypeScript best practices. This document serves as the
knowledge base for the nodejs-doc-comments pattern.
Table of Contents
- Core Principles
- Syntax by Declaration Type
- JSDoc Tags Reference
- What to Document
- Common Mistakes
- Quality Checklist
Core Principles
The Golden Rule
JSDoc blocks appear immediately before the export/declaration with no
intervening blank lines. All exported names that carry non-obvious meaning
should have JSDoc blocks. Trivial getters/setters and re-exports are
intentionally left undocumented — a block that only restates the name is a
defect, not a fix.
Philosophy
| Principle | Description |
|---|
| Complete sentences | Start with an action verb or noun phrase |
| Explain what | Not how it works internally |
| User focus | Focus on caller needs, not implementation |
| Searchable | Clear, explicit, searchable text |
| No redundancy | Avoid "processData — processes the data" |
| Add value | Provide info beyond the function signature |
Line Length
All comment lines should stay within 80 characters for readability.
Syntax by Declaration Type
Functions
export async function getUserById(id: string): Promise<User | null> {
}
Rules:
- Start with an imperative verb: "Fetches...", "Creates...", "Returns...",
"Validates..."
@param name - description (dash separator, not colon)
@returns describes what is returned and when null/undefined is possible
- Omit TypeScript types in
@param and @returns for .ts files — the
type system is the source of truth
Classes
export class ConnectionPool {
constructor(private readonly config: PoolConfig) {}
}
Rules:
- Use "Manages...", "Represents...", "Provides..."
- Document concurrency safety explicitly when relevant
- Document cleanup requirements (
.close(), .destroy())
Interfaces and Type Aliases
export interface HttpClientOptions {
baseUrl: string;
timeout?: number;
}
export type PaginatedResponse<T> = {
data: T[];
total: number;
page: number;
};
Constants and Enums
export const MAX_RETRIES = 3;
export const RETRY_DELAY_MS = 500;
export enum HttpStatus {
OK = 200,
NotFound = 404,
InternalServerError = 500,
}
Error Variables / Sentinel Errors
export class NotFoundError extends Error {}
export const ErrNotFound = new Error('not found');
Boolean Functions
export function isValidEmail(email: string): boolean {}
export function isActiveUser(user: User): boolean {}
JSDoc Tags Reference
Core Tags
| Tag | Usage | Example |
|---|
@param name - desc | Document a parameter | @param id - The user UUID |
@returns desc | Document return value | @returns The matching user or null |
@throws {Type} desc | Document thrown errors | @throws {ValidationError} If input is invalid |
@example | Code example block | See below |
@deprecated desc | Mark as deprecated | @deprecated Use createClientV2 instead |
@remarks desc | Additional context | @remarks Not safe for concurrent use |
@see | Cross-reference | @see {@link getUserById} |
@since version | Version introduced | @since 2.0.0 |
@example Tag
export function decodeJwt(token: string): JwtPayload {}
@deprecated Tag
export function createHttpClient(url: string): HttpClient {}
TypeScript-Specific Conventions
For .ts files, omit types from @param and @returns — they are
redundant with the TypeScript signature:
async function getUser(userId: string): Promise<User | null>
async function getUser(userId: string): Promise<User | null>
For .js files (no TypeScript), include types:
async function getUser(userId) {}
What to Document
Async / Promise Behavior
Document when non-standard:
export async function sendEmail(to: string, subject: string): Promise<void> {}
Error Values
export class RateLimitError extends Error {
retryAfter: number;
}
Cleanup Requirements
export async function connect(url: string): Promise<BrokerClient> {}
Parameter Constraints
export function schedule(intervalMs: number, fn: () => Promise<void>): Job {}
Return Value Semantics
export async function searchUsers(filter: UserFilter): Promise<PaginatedResult<User>> {}
Common Mistakes
Redundant Comments
Bad:
export function getUser(id: string): Promise<User> {}
Good:
export function getUser(id: string): Promise<User> {}
Best (when the name already says it all): add no block. For trivial
getters/setters or re-exports, leaving the declaration undocumented is
correct — list it as trivial in the skipped table. A lateral rewrite of an
already-adequate block is not an improvement either; leave it alone.
Implementation Details
Bad:
export function getUser(id: string): Promise<User> {}
Good:
export function getUser(id: string): Promise<User> {}
Blank Line Between JSDoc and Declaration
Bad:
export function getUser(id: string): Promise<User> {}
Good:
export function getUser(id: string): Promise<User> {}
Missing @throws
Bad:
export function parseJson(raw: string): unknown {}
Good:
export function parseJson(raw: string): unknown {}
Special Syntax
Deprecation
export function createClient(): Client {}
Doc Links (TypeDoc / TSDoc)
export function createSession(token: string): Session {}
Module-Level Documentation
Tools and Automation
TypeDoc
Generate HTML docs from JSDoc + TypeScript types:
npm install --save-dev typedoc
npx typedoc --entryPoints src/index.ts --out docs
TSDoc Linter
npm install --save-dev @microsoft/tsdoc @microsoft/tsdoc-config
ESLint JSDoc Plugin
npm install --save-dev eslint-plugin-jsdoc
module.exports = {
plugins: ['jsdoc'],
rules: {
'jsdoc/require-jsdoc': ['warn', { publicOnly: true }],
'jsdoc/require-param-description': 'warn',
'jsdoc/require-returns-description': 'warn',
},
};
Quality Checklist
Before Submitting
Common Patterns
| Declaration | Pattern |
|---|
async function returning value | "Fetches...", "Creates...", "Resolves..." |
function returning bool | "Returns true if [condition]" |
function with side effects | "[Action]s [object]..." |
class | "Manages...", "Represents...", "Provides..." |
| Error class/constant | "[Name] is thrown when..." |
| Constant | "[Name] is the [purpose]..." |
| Type alias | "Represents..." |
References
Last updated: 2026-05-25