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 🙏

© 2025 – Pkg Stats / Ryan Hefner

serverless-fastify

v0.3.2

Published

A fastify wrapper around the Serverless framework

Readme

Serverless Fastify

Simple wrapper around Fastify to use it with Serverless

Disclaimer: very EARLY draft of the package, thus I may introduce breaking changes between versions

Prerequisites

  • TypeScript
  • Fastify

Install

Install with npm:

npm i serverless-fastify --save

Example

hello-world-controller.ts

import { Get } from "serverless-fastify";
import { FastifyRequest, FastifyReply } from "fastify";

// Define the controller using the interface
export class HelloWorldController {
  @Get("/", {
    schema: {
      response: {
        200: {
          type: "object",
          properties: {
            msg: { type: "string" },
          },
        },
      },
    },
  })
  getMessage(request: FastifyRequest, reply: FastifyReply<any>) {
    return {
      msg: "Hello world",
    };
  }
}

sls-fastify-config.ts

import { SlsFastifyConfig } from "serverless-fastify";
import { HelloWorldController } from "./hello-world.controller";

// Pre handler hook plugin example ( may be turned into class + decorator later )
const preHandlerHook = (fastify, options, done) => {
  fastify.addHook("preHandler", (request, reply, done) => {
    console.log("Pre handler hook !");
    done();
  });
  done();
};

// Define the config here
const slsFastifyConfig = {
  // Define the routes
  routes: [
    {
      name: "helloworld", // This is the name of the handler in serverless.yml
      controller: HelloWorldController, // the actual controller for this route
      prefix: "v1/helloworld", // The prefix defined for api gateway
    },
  ],
  // Registering the fastify plugins ( the order matters )
  plugins: [preHandlerHook],
} as SlsFastifyConfig;

export { slsFastifyConfig };

handlers.ts

import { initHandlers } from "serverless-fastify";
import { slsFastifyConfig } from "./sls-fastify-config"; // Your config

// Register the handlers for serverless
export = {
  ...initHandlers(slsFastifyConfig, async () => {
    // Any async code before execution the handlers ( in serverless )
    // e.g initDatabaseConnection()
  }),
};

server.ts ( To run the server locally )

import { initApp } from "serverless-fastify";
import { slsFastifyConfig } from "./sls-fastify-config"; // Your config

async function start() {
  const PORT = Number(process.env.port) || 3000;
  const HOST = process.env.host || "127.0.0.1";

  const app = initApp(slsFastifyConfig);

  app.listen(PORT, HOST, async (err) => {
    if (err) console.error(err);
    console.log(`server listening on port ${PORT}`);
  });
}

start();

serverless.yml

service: sls-fastify

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage, 'dev'}
  region: eu-west-1
  stackName: ${self:service}-${self:provider.stage}
  apiName: ${self:service}-${self:provider.stage}
  timeout: 29

functions:
  helloworld:
    handler: handlers.helloworld
    events:
      - http: "ANY /v1/helloworld"
      - http: "ANY /v1/helloworld/{proxy+}"


plugins:
  - serverless-webpack

License

Licensed under MIT