As first adopters tinker with Deno, many people are trying to figure out tooling that parallels what they’re used to in node. If you’re looking for a lightweight web application framework like express.js, you probably want to explore oak.
Note: Many of the examples in this post are taken from the github documentation!
Oak is self-described as “A middleware framework for Deno’s http server, including a router middleware.”
To be completely transparent, oak is actually much more similar to koa for node than express.js, but express users should be very comfortable with oak.
To create a “Hello World!” app in deno with oak, we import Application
from the oak module. You create a new instance of the app, add a handler for all requests that set the response body to "Hello World!"
, and then listen on a port.
Make sure to pin down the version of oak in your import statement! Here it’s pinned down to version 4.0.0.
import { Application } from 'https://deno.land/x/oak@v4.0.0/mod.ts';
const app = new Application();
app.use(ctx => {
ctx.response.body = 'Hello World!';
});
await app.listen({ port: 8000 });
Now if you browse to http://localhost:8000
, you should see our Hello world!
message!
#deno #node #javascript #typescript #web-development