Documentation

@server/next tests

A web server for Bun, Node.js and Functions/Workers with the basics built-in:

import server from "@server/next";

export default server(options)
  .get("/books", () => Book.list())
  .post("/books", (ctx) => {
    return Book.create(ctx.body).save();
  });

It includes all the things you would expect from a modern Server framework, like routing, static file serving, body+file parsing, streaming, testing, error handling, websockets, etc.

We also have integrations and adaptors for these:

  • KV Stores: in-memory, Redis, Consul, DynamoDB, Level.
  • Buckets: AWS S3, Cloudflare R2, Backblaze B2.
  • Auth: Cookie sessions, Bearer tokens, JWT, API keys, Social login, Email/password.
// index.test.js
// How to test your server with the built-in methods
import app from "./";  // Import your normal app
// Convenient helper; each call returns a standard Response
const api = app.test();

it("can retrieve the book list", async () => {
  const res = await api.get("/books/");
  expect(res.status).toBe(200);
  const books = await res.json();
  expect(books[0]).toEqual({ id: 0, name: ... });
});

Getting started

First install it:

npm install @server/next
bun add @server/next

That's everything: key-value stores and file storage come with it, so store takes a plain Map and uploads takes a folder path. See Dependencies for Redis, S3 and the rest.

Now you can create your first simple server:

// index.js
import server from "@server/next";

export default server()
  .get("/", () => "Hello world")
  .post("/", (ctx) => {
    console.log(ctx.body);
    return 201;
  });

Then run node . or bun . and open your browser on http://localhost:3000/ to see the message.

See Basic usage for the configuration options you'll most likely want next.