DEV Community

Dario Castañé
Dario Castañé

Posted on

Simple Deno HTTP server running in Nanos unikernel

This short post shows how to get a self-executable Deno HTTP server to run in Nanos using Ops.

The server

const port = Number(Deno.env.get('PORT'));
const listener = Deno.listen({ port: port });


for await (const conn of listener) {
  (async () => {
    const requests = Deno.serveHttp(conn);
    for await (const { respondWith } of requests) {
      respondWith(new Response("Hello world"));
Enter fullscreen mode Exit fullscreen mode

Compilation and local deployment

deno compile --allow-env --allow-net hello.ts
ops run -e HOME=/ -e PORT=8000 -p 8000 hello
Enter fullscreen mode Exit fullscreen mode

The trick is to set the HOME variable. It can have any value, but / feels right.


In this post, we have seen a minimal Deno HTTP server working in a Nanos unikernel.

Discussion (0)