Skip to content

Instantly share code, notes, and snippets.

@nikolaybotev
Last active October 26, 2024 15:09
Show Gist options
  • Save nikolaybotev/3ce483bd1ceb3610f2ec85d4103c79f9 to your computer and use it in GitHub Desktop.
Save nikolaybotev/3ce483bd1ceb3610f2ec85d4103c79f9 to your computer and use it in GitHub Desktop.
Deno serve over unix socket example with socket file cleanup
const socketPath = "/tmp/mock-server";
// Needed if starting with node --watch
try {
await Deno.remove(socketPath);
} catch (e) {
// ignore
}
let server = Deno.serve({ path: socketPath }, (_req) => new Response("Hello, world."));
// Graceful shutdown (not invoked on deno --watch restarts)
Deno.addSignalListener("SIGINT", async () => {
console.log("Shutting down server...");
await server.shutdown();
await Deno.remove(socketPath);
console.log("Shut down server.");
Deno.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment