@nodefactory/fastify-blipp

2.2.1 • Public • Published

fastify-blipp prints your routes to the console. So each time your server starts, you know which endpoints are available.

(inspired by blipp hapijs plugin)

install

npm i fastify-blipp

usage

It is important to register the plugin as soon as possible, so it starts to listen for the new routes.

const fastify = require("fastify")();

// register it as early as possible
fastify.register(require("fastify-blipp"));

fastify.get("/hello/:username", async (req, reply) => ({
  greeting: `Hello, ${req.params.username}`
}));
fastify.get("/hello/:username/CAPS", async (req, reply) => ({
  greeting: `Hello, ${req.params.username.toUpperCase()}`
}));
fastify.post("/hello", async (req, reply) => ({
  greeting: `Hello, ${req.body.username}`
}));
fastify.get(
  "/example/at/:hour(^\\d{2})h:minute(^\\d{2})m",
  async (req, reply) => ({
    hour: req.params.hour,
    minute: req.params.minute
  })
);

const start = async () => {
  try {
    await fastify.listen(3000);

    fastify.blipp();

    console.log(`server listening on ${fastify.server.address().port}`);
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
};

start();

result

image

Dependencies (2)

Dev Dependencies (7)

Package Sidebar

Install

npm i @nodefactory/fastify-blipp

Weekly Downloads

0

Version

2.2.1

License

ISC

Unpacked Size

247 kB

Total Files

8

Last publish

Collaborators

  • makmuftic
  • mpetrunic
  • morrigan88