npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@didik-mulyadi/nodejs-api-doc

v1.2.0

Published

A nodejs library to generate the API Docs with multiple UI

Downloads

919

Readme

This package already supports NestJS and ExpressJS. At this point, we are focusing on adding examples with many js-doc libraries. In the future, we will create our open API doc generation, "One Code for All Frameworks", but don't worry we are still making it support with other libraries.

Installation 🚀

Install @didik-mulyadi/nodejs-api-doc using pnpm/npm/yarn:

pnpm add @didik-mulyadi/nodejs-api-doc

# OR

npm install @didik-mulyadi/nodejs-api-doc

# OR

yarn add @didik-mulyadi/nodejs-api-doc

Usage 💻

After we set up the package correctly, we can switch the UI in your docs with this.

For example, your API doc location is `http://localhost:3000/docs

  1. Use Swagger UI, http://localhost:3000/docs?ui=swagger

image

  1. Use Stoplight UI, http://localhost:3000/docs?ui=stoplight

image

  1. Use Redoc UI, http://localhost:3000/docs?ui=redoc

image

For code examples, see the examples directory or click.

Compatibility ⚙️

This package supports any package/library that returns the open API object. These are tested framework and library that is compatible with our package:

| Library | Support | | -------------------------------------------------------------------------------------- | ------- | | Nest JS + Fastify with @nestjs/swagger | ✅ | | Nest JS + Express with @nestjs/swagger | ✅ | | Express with swagger-jsdoc | ✅ |

Implementation 💻

Here's an example of how to use this package:

nodejs-api-doc with Nest Fastify + @nest/swagger

Step:

  1. Modify your src/main.ts with the below steps
  2. Create a swagger config with new DocumentBuilder()
  3. Generate open API document object with SwaggerModule.createDocument(app, config)
  4. Setup nodejs-api-doc with new NestApiDoc
  5. Start nodejs-api-doc with nestApiDoc.start()
import { NestApiDoc } from '@didik-mulyadi/nodejs-api-doc'

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter()
  )
  // swagger
  const config = new DocumentBuilder()
    .setTitle('Node.js API Docs')
    .setDescription('This API provides ...')
    .setVersion('0.0.1')
    .build()
  const document = SwaggerModule.createDocument(app, config)

  // nodejs-api-doc
  const nestApiDoc = new NestApiDoc(app, document, {
    defaultUI: 'stoplight',
    customPath: '/docs',
  })
  nestApiDoc.start()

  // Run the nestjs
  await app.listen(8080, '0.0.0.0')
}

nodejs-api-doc with Nest Express + @nest/swagger

Step:

  1. Modify your src/main.ts with the below steps
  2. Create a swagger config with new DocumentBuilder()
  3. Generate open API document object with SwaggerModule.createDocument(app, config)
  4. Setup nodejs-api-doc with new NestApiDoc
  5. Start nodejs-api-doc with nestApiDoc.start()
import { NestApiDoc } from '@didik-mulyadi/nodejs-api-doc'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  // swagger
  const config = new DocumentBuilder()
    .setTitle('Node.js API Docs')
    .setDescription('This API provides ...')
    .setVersion('0.0.1')
    .build()
  const document = SwaggerModule.createDocument(app, config)

  // nodejs-api-doc
  const nestApiDoc = new NestApiDoc(app, document, {
    defaultUI: 'stoplight',
    customPath: '/docs',
  })
  nestApiDoc.start()

  // Run the nestjs
  await app.listen(8080, '0.0.0.0')
}

nodejs-api-doc with Express + swagger-jsdoc

Step:

  1. Modify your server.js or main.js with the below steps
  2. Call the swagger-jsdoc const document = swaggerJsdoc(options)
  3. Setup nodejs-api-doc const expressApiDoc = new ExpressApiDoc(app, document)
  4. Start nodejs-api-doc expressApiDoc.start()
const { ExpressApiDoc } = require('@didik-mulyadi/nodejs-api-doc')

const app = express()

...

// swagger-jsdoc
const options = {
  definition: {
    openapi: '3.1.0',
    info: {
      title: 'Node JS API Docs with Express',
      version: '0.1.0',
      description:
        'This is a simple CRUD API application made with Express and documented with Swagger',
      license: {
        name: 'MIT',
        url: 'https://spdx.org/licenses/MIT.html',
      },
      contact: {
        name: 'Didik Mulyadi',
        url: 'https://www.linkedin.com/in/didikmulyadi/',
        email: '[email protected]',
      },
    },
    servers: [
      {
        url: 'http://localhost:3000',
      },
    ],
  },
  apis: ['./routes/*.js'],
}
const document = swaggerJsdoc(options)

// Nodejs-api-doc
const expressApiDoc = new ExpressApiDoc(app, document)
expressApiDoc.start()

app.listen(3000)

Configuration options ⚙️

Working with Helmet

Nest.JS Fastify Helmet

import { NestApiDoc, helmetConfig } from '@didik-mulyadi/nodejs-api-doc';

async function bootstrap() {
  ...
  await app.register(helmet, helmetConfig.nodeApiDocHelmetOption);
  ...
}

Bugs or Requests 🐛

If you found any issues or have a good suggestion, feel free to open an issue

TODO

We are still updating this package, to make it more useful and easy to use. Here are the next that author wants to do

  • [ ] Add readme for bug_report.md
  • [ ] Add readme for feature_request.md

Find Me 📖

Reach me on:

LinkedIn Medium