Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fastify-print-routes

ShogunPanda35.4kISC4.1.0TypeScript support: included

A simple plugin for Fastify prints all available routes.

fastify, fastify-plugin, print, routes

readme

fastify-print-routes

Version Dependencies Build Coverage

A simple plugin for Fastify prints all available routes.

http://sw.cowtech.it/fastify-print-routes

Installation

Just run:

npm install fastify-print-routes --save

Usage

Register as a plugin as early as possible, optional providing any of the following options:

  • useColors: If to use colors to highlight routes.
  • compact: If to show all routes of the same path in a single line even if they are defined using different handlers. Descripion of unified routes will not be printed.
  • filter: If provided, a function that receives a route and should return a boolean to determine if the route should be print or not.
  • querystring: If to include querystrings in the URLs.

Routes can also be omitted by the list by setting hide option to true inside their config.

Once the server is started, it will print on the console all available routes and methods.

Example

import fastify from 'fastify'
import fastifyPrintRoutes from 'fastify-print-routes'

const server = fastify()

/*
Since fastify-print-routes uses an onRoute hook, you have to either:

* use `await register...`
* wrap you routes definitions in a plugin

See: https://www.fastify.io/docs/latest/Guides/Migration-Guide-V4/#synchronous-route-definitions
*/
await server.register(fastifyPrintRoutes)

server.get('/path1', {
  async handler() {
    return { ok: true }
  }
})

server.route({
  url: '/path2/:params',
  method: ['POST', 'GET'],
  async handler() {
    return { ok: true }
  },
  config: {
    description: 'Title'
  }
})

server.route({
  url: '/path3',
  method: ['POST', 'GET'],
  async handler() {
    return { ok: true }
  },
  config: {
    hide: true
  }
})

server.listen({ port: 3000 }, () => {
  console.log(`Server listening on port ${server.server.address().port} ...`)
})

Once started, this will be printed to the console:

Available routes:

╔════════════╤════════════════╤═════════════╗
║  Method(s) │ Path           │ Description ║
╟────────────┼────────────────┼─────────────╢
║        GET │ /path1         │             ║
║       HEAD │ /path1         │             ║
║ GET | POST │ /path2/:params │ Title       ║
╚════════════╧════════════════╧═════════════╝

Server listening on port 60792 ...

ESM Only

This package only supports to be directly imported in a ESM context.

For informations on how to use it in a CommonJS context, please check this page.

Contributing to fastify-print-routes

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

Copyright (C) 2020 and above Shogun (shogun@cowtech.it).

Licensed under the ISC license, which can be found at https://choosealicense.com/licenses/isc.

changelog

2025-03-09 / 4.1.0

  • feat: Added decorator.

2024-12-28 / 4.0.1

  • chore: Updated dependencies.

2024-10-21 / 4.0.0

  • feat: Support zod schemas.
  • feat!: Dropped support for Node 18 and updated dependencies.

2024-04-12 / 3.2.0

  • chore: Updated dependencies.
  • feat: Add querystring option.
  • chore: Added missing dependency.

2024-02-07 / 3.1.1

  • chore: Updated dependencies.
  • chore: Improved tests.

2024-02-06 / 3.1.0

  • chore: Replace tap with Node test runner.
  • feat: Added filter option.
  • feat: Include querystring in the URL.

2024-01-27 / 3.0.2

  • chore: Updated dependencies.

2024-01-24 / 3.0.1

  • chore: Updated TypeScript configuration.

2023-12-20 / 3.0.0

  • chore: Updated dependencies.
  • chore: Changed TypeScript version.

2023-10-23 / 2.2.0

  • chore: Updated dependencies and toolchain.
  • chore: Fixed compilation.

2023-02-22 / 2.1.0

  • feat: Added compact option.
  • chore: CI improvement

2022-11-23 / 2.0.7

  • chore: Updated dependencies.
  • chore: Update package.json
  • fix: Fixed build script.

2022-10-12 / 2.0.6

  • chore: Updated dependencies.

2022-10-12 / 2.0.5

  • fix: Updated types layout.
  • chore: Updated compilation configuration.

2022-08-30 / 2.0.4

  • chore: Updated dependencies.

2022-08-30 / 2.0.3

  • fix: Improved README.

2022-08-30 / 2.0.2

  • fix: Fixed README.

2022-08-30 / 2.0.1

  • fix: Require fastify version.

2022-08-30 / 2.0.0

  • feat: Updated to fastify 4.
  • chore: Use sourcemaps with swc

2022-03-07 / 1.0.5

  • chore: Updated dependencies.

2022-03-07 / 1.0.4

  • chore: Updated build system.

2022-01-26 / 1.0.3

  • chore: Updated dependencies and linted code.
  • chore: Updated dependencies.
  • chore: Removed useless file.

2021-11-17 / 1.0.2

2021-11-16 / 1.0.1

  • fix: Added ESM note in the README.md
  • chore: Allow manual CI triggering.
  • chore: Updated badges.
  • fix: Fixed Typescript configuration.

2021-08-16 / 1.0.0

2021-08-16 / 1.0.0-beta.0

  • chore: Added missing file.
  • feat: Only export as ESM.

2021-01-19 / 0.4.1

  • chore: Added PNPM configuration.
  • chore: Use a onReady hook rather than .ready.
  • chore: Fine tuned build script.

2021-01-04 / 0.4.0

  • feat: Export as ESM.

2021-01-03 / 0.3.1

  • chore: Updated linter config.

2021-01-02 / 0.3.0

  • chore: Updated dependencies, code and tools.

2021-01-01 / 0.2.1

  • fix: Removed useless comparison.

2020-12-31 / 0.2.0

  • chore: Fix dependencies list.
  • feat: Omit description column if not needed.

2020-12-31 / 0.1.0

  • Initial version.