Super Simple Fastify Server

1.0.0 · active · verified Tue Apr 21

This library, `super-simple-fastify-server`, currently at version 1.0.0, provides a lightweight and opinionated wrapper around the Fastify web framework. It is designed for rapidly spinning up temporary or local development servers with minimal boilerplate and configuration, making it ideal for testing, prototyping, or quickly standing up mock APIs. The package's primary goal is to simplify server creation by abstracting common Fastify setup, allowing developers to focus solely on defining routes. It features configurable host and port settings that can be controlled via constructor options or environment variables, prioritizing ease of use over extensive customization. While new and without an established release cadence, it offers a stable API for its current scope and ships with TypeScript type definitions for enhanced developer experience. A key differentiator is its minimal footprint, leveraging Fastify and `pino-pretty` as peer dependencies, giving users control over specific versions of these core components.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `SimpleFastifyServer`, define a basic GET route, and start the server on a specified host and port.

import { FastifyInstance, SimpleFastifyServer } from 'super-simple-fastify-server';

const server = new SimpleFastifyServer(
    async (app: FastifyInstance) => {
        app.get('/hello-world', async (request, _reply) => {
            return { message: `Hello, ${request.query.target}!` };
        });
    },
    {
        host: '127.0.0.1',
        port: 3456
    }
);

(async () => {
  await server.start();
  console.log(`Server listening at http://${server.config.host}:${server.config.port}`);
  // To stop the server later:
  // await server.stop();
})();

view raw JSON →