ajcwebdev

five deno web frameworks - deno http

denonodehttpframeworks

When building a web server with NodeJS, most developers use a framework such as Express, Koa, or (the newly resurrected) Hapi. There are many frameworks currently being built for Deno that take inspiration from Node frameworks and frameworks from other languages like Flask or Sinatra.

Popularity is not always the best metric, but when it comes to open source projects it signals a greater level of developers are working with a framework which means more bug fixes, more feature requests, and more resources online to learn that framework. The five most popular frameworks right now are:

  1. Oak
  2. Drash
  3. Servest
  4. Opine
  5. abc

Craig Morten's excellent overview What Is The Best Deno Web Framework? explores these five frameworks along with a range of others.

Deno HTTP

Before diving into the frameworks it's useful to see the underlying server code they are building upon. The Deno Standard Library has an http module with a basic hello world application. First make sure you have Deno installed.

Create project directory and hello.ts

mkdir ajcwebdev-deno
cd ajcwebdev-deno
touch hello.ts

Save the following code in hello.ts:

// hello.ts

import { serve } from "https://deno.land/std/http/server.ts"

const server = serve({ port: 8000 })

for await (const req of server) {
req.respond({
body: "<h1>Hello World<h1>"
})
}

Run Deno server

deno run --allow-net hello.ts

Open your browser to localhost:8000

01-deno-hello-world

We can contrast this with a similar example in Node. Save the following code in a file called hello.js:

// hello.js

const http = require('http');

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end('<h1>Hello World</h1>');
});

server.listen(3000);

Run Node server

node hello.js

Open your browser to localhost:3000.

02-node-hello-world