Skip to content

Express TS meta framework that designed with developer experience in mind

License

Notifications You must be signed in to change notification settings

zephyr-js/zephyr

Repository files navigation

Zephyr.js logo

Zephyr.js

Build Typesafe Node API in minutes

Zephyr.js CI workflow CodeFactor

Description

Zephyr is a Typescript server-side meta framework that is inspired by Next.js for its file-based routing. It is built on top of Express.js and uses Zod in request / response validation as well as providing typesafe API.

Zephyr places a high value on FP (Functional Programming). Instead of using classes as API controllers, declare and export API routes with functions.

Philosophy

The established server-side web frameworks for Node.js at the moment are Nest.js and Adonis.js, both of which are fantastic and rely on controllers and decorators in OOP. However, some programmers prefer functional programming to object-oriented programming (OOP). As a result, Zephyr seeks to let programmers to define API routes with functions and provides file-based routing out of the box.

Getting started

Kindly visit our documentation on zephyrjs.com

Overview

Bootstrapping Project

npm create zephyr-app <app-name>
yarn create zephyr-app <app-name>
pnpm create zephyr-app <app-name>

Defining API Route

// src/routes/login.ts

import { defineRoute } from '@zephyr-js/core';

// POST /login
export function POST() {
  return defineRoute({
    schema: z.object({
      body: z.object({
        email: z.string(),
        password: z.string(),
      }),
      response: z.object({
        success: z.boolean(),
      }),
    }),
    onRequest(req) {
      logger.info('Request received', req.method, req.path);
    },
    async handler({ body }) {
      await login(body);
      return { success: true };
    },
    onErrorCaptured(req, res, err) {
      logger.error('Login failed', err);
      res.status(500);
      return { success: false };
    },
  });
}

TODO

  • Complete create-zephyr-app
  • Publish @zephyr-js/core, @zephyr-js/common and create-zephyr-app to NPM
  • Create unit tests
  • Supports dependency injection
  • Create zephyr cli