Oak is a modern web framework created especially for the modern Deno.js runtime. This framework mainly focuses on routing and middleware inspired by Koa and Express frameworks. It is de facto the most popular web framework for Deno.js runtime to date.
In consequence, if we already have enough experiences in Express, there will not be a problem for us to use Oak framework because as mentioning above, Oak framework based on the same principles of routing and middleware.
To start using Oak framework, we need to install Deno.js runtime first by writing command as below:
// Using Shell (macOS and Linux):
curl -fsSL https://deno.land/x/install/install.sh | sh
// Using PowerShell (Windows):
iwr https://deno.land/x/install/install.ps1 -useb | iex
Next, we are going to create the bare minimal web application using Oak web framework.
import { Application } from "https://deno.land/x/oak/mod.ts"
const app = new Application()
app.use((ctx) => {
ctx.response.body = "Deno web application with Oak framework!"
})
await app.listen({ port: 8000 })
To run this application, we can write the command on Terminal window as below:
deno run --allow-net app.js
The output of this application will be printed on the browser if we open it at the web address http://localhost:8000 .