Skip to content
/ sact Public

Simple and fast node websocket and http framework

License

Notifications You must be signed in to change notification settings

mtsewrs/sact

Repository files navigation

⚡️ Minimal and fast node framework

NPM Version NPM Downloads

Sact

Core features

  • Async first
  • Middleware support
  • Plugin system
  • Body parsing

Core plugins

  • @sact/cookie - Cookie parsing
  • @sact/session - Sessions using redis or in-memory
  • @sact/auth - Opinionated authentication
  • @sact/graphql - Graphql
  • @sact/shine - Shine (opinionated json-rpc api sub-framework)

API documentation are heavily lacking but generated ones by typedoc are located in each package under /docs. You can also look at the tests for each package for usage but the main server package is @sact/core the rest are plugins for various cases, use it if you want

Install

  yarn add @sact/core

Minimal setup

import { Sact } from '@sact/core';

const app = new Sact();

app.get('/', async () => ({ foo: 'bar' }));

async function start() {
  try {
    // a automatic port will be chosen for you
    const { url } = await app.listen();
    console.log('Server started on ', url);
  } catch (error) {
    console.error(error);
  }
}

start();

Middlewares

app.use((req, res) => {
  req.foo = 'bar';
  console.log(`Requested route ${req.getUrl()}`);
});

app.get('/foo', async (req) => req.foo);

Plugins

// register middlewares or routes here
const plugin = (app, options) => {
  app.foo = 'bar';

  app.use((req, res) => {
    console.log(`Requested route ${req.getUrl()}`);
  });

  app.get('/foo', async () => app.foo);
};

app.register(plugin, {});

This framework uses https://github.com/uNetworking/uWebSockets

About

Simple and fast node websocket and http framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published