Skip to main content
Documentation is as critical as the code itself. Without good documentation, developers cannot onboard, APIs cannot be consumed, and future maintainers cannot understand decisions. This page covers JSDoc for code-level documentation, Swagger/OpenAPI for interactive API reference, and best practices for READMEs and changelogs.

Why Document Your API

Faster Onboarding

New team members make their first successful API call in minutes, not days.

API Contracts

Frontend and backend teams agree on endpoints, payloads, and error responses before writing code.

Better Testing

QA engineers and integration partners use docs to build test suites.

Maintenance

Six months from now, documented edge cases save hours of debugging.

Types of Documentation

JSDoc

JSDoc is a markup language for annotating JavaScript. It generates structured HTML documentation from specially formatted comments.

JSDoc Annotations Reference

Annotated Function Example

Generate HTML Docs

Swagger / OpenAPI

OpenAPI is the specification standard for describing REST APIs in YAML or JSON. Swagger is the tooling ecosystem around it.

Install

Setup in app.js

Documenting a Route

Place @swagger comments above or near the route handler:
Visit http://localhost:3000/api-docs to see the interactive Swagger UI where you can test every endpoint.

Postman Documentation

  1. Build a Postman collection with all your API requests
  2. Click the collection > ... > Publish Docs
  3. Postman generates a shareable URL with styled documentation
  4. Keep it updated: after any API change, update the Postman request
Frontend developers can import the collection and start making requests immediately.

README Best Practices

A standard README structure:

Environment Setup

Copy the template and fill in your values:
Required variables: PORT, DB_URI, JWT_SECRET

Running the Application

API Overview

Full interactive docs: http://localhost:3000/api-docs

Contributing

  1. Fork the repository
  2. Create a branch: git checkout -b feature/your-feature
  3. Commit: git commit -m 'Add your feature'
  4. Push: git push origin feature/your-feature
  5. Open a Pull Request

Error Code Reference Table

Include this in your README or API docs:

Key Terms

Common Mistakes

Outdated docs mislead consumers. Treat @swagger comments as part of the route. Review them in every code review.
If you omit security: [{ bearerAuth: [] }] from a protected route, developers test without tokens, get 401, and don’t understand why.
A changelog only covering the last two releases is useless. Make updating it a required step in your release process alongside version bumping.
A repository without a README is uninviting and forces every new person to read all the source code. Even a minimal README with setup steps saves hours.