Skip to content

Instantly share code, notes, and snippets.

@ondras
Last active April 12, 2020 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ondras/da180377364bbfe5515051a24300ca4e to your computer and use it in GitHub Desktop.
Save ondras/da180377364bbfe5515051a24300ca4e to your computer and use it in GitHub Desktop.
Deno example
import { serve, ServerRequest } from "https://deno.land/std@master/http/server.ts";
const body = "<img src=https://deno.land/images/deno_logo.png>";
const port = Deno.args[0] || "8888";
function processRequest(req: ServerRequest) {
req.respond({body});
}
for await (const req of serve(`:${port}`)) {
processRequest(req);
}
#!/bin/sh
DENO=https://github.com/denoland/deno/releases/download/v0.40.0/deno-x86_64-unknown-linux-gnu.zip
FILE=https://gist.githubusercontent.com/ondras/da180377364bbfe5515051a24300ca4e/raw/991879cc34eefeaf327c3aed205e88dc6cbda3d6/01-server.ts
curl -L $DENO | gzip -d > deno
chmod +x deno
./deno --allow-net -r $FILE

Deno features

  • Single executable
  • Sandbox (env, fs, net, r/w)
  • No package.json
  • No npm
  • TypeScript
  • ES6 modules
  • No callbacks, Yes promises/async/await
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment