Documenting Node.js API using Swagger

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • OpenAPI-Specification

    The OpenAPI Specification Repository

  • In this article, we will be learning how to document API written in Node.js using a tool called Swagger. Swagger allows you to describe the structure of your APIs so that machines can read them. The ability of APIs to describe their own structure is the root of all awesomeness in Swagger. Why is it so great? Well, by reading our API’s structure, swagger can automatically build beautiful and interactive API documentation. It can also automatically generate client libraries for your API in many languages and explore other possibilities like automated testing. Swagger does this by asking our API to return a YAML or JSON that contains a detailed description of your entire API. This file is essentially a resource listing of our API which adheres to OpenAPI Specifications.

  • node-js-swagger

    A Node.js API use to demonstrate API documentation in swagger UI

  • import swaggerJsdoc from 'swagger-jsdoc' import swaggerUi from 'swagger-ui-express' const options = { definition: { openapi: '3.0.0', info: { title: 'Mini Blog API', description: "API endpoints for a mini blog services documented on swagger", contact: { name: "Desmond Obisi", email: "[email protected]", url: "https://github.com/DesmondSanctity/node-js-swagger" }, version: '1.0.0', }, servers: [ { url: "http://localhost:8080/", description: "Local server" }, { url: "", description: "Live server" }, ] }, // looks for configuration in specified directories apis: ['./router/*.js'], } const swaggerSpec = swaggerJsdoc(options) function swaggerDocs(app, port) { // Swagger Page app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)) // Documentation in JSON format app.get('/docs.json', (req, res) => { res.setHeader('Content-Type', 'application/json') res.send(swaggerSpec) }) } export default swaggerDocs

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts