Getting started
Nelo keeps application code on Web Standards and places Node transport behavior behind nelo/node.
Nelo is experimental. The current package line is
0.2.0-alpha and APIs may change before a stable release.Create an application
import { Nelo } from "nelo";
import { serve } from "nelo/node";
const app = new Nelo();
app.get("/", (context) => {
return context.json({ message: "Hello from Nelo" });
});
const server = serve(app, {
hostname: "127.0.0.1",
port: 3000,
});
const address = await server.listen();
console.log(address);Start owned work
context.fork() creates eager work owned by the current request. Pass the supplied signal into cancellable APIs.
app.get("/users/:id", async (context) => {
const user = context.fork((signal) =>
fetchUser(context.params.id, { signal })
);
return context.json(await user);
});Register resources
context.use() binds cleanup to the handler lifetime and disposes resources in reverse acquisition order.
app.get("/report", async (context) => {
const database = await openDatabase();
context.use(() => database.close());
return context.json(await createReport(database));
});Close gracefully
await server.close({
gracePeriod: 5_000,
forceAfter: 10_000,
});The server stops accepting new connections, waits during the grace period, propagates server_shutdown, and destroys remaining sockets only at the hard deadline.