Skip to content

Deno notes

Deno is JavaScript for the serverless era.

HTTP server

Examples using the HTTP server from the built in Deno standard library.

https://deno.com/deploy/docs/examples

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

JSX

Preact

This can be extended to render from JSX by including Preact and preact-render-to-string.

https://deno.com/deploy/docs/examples#ssr-jsx-preact

Note that some examples use a .jsx or .tsx file extension, so Deno Deploy knows to interpret a given file as JSX/TSX.

Nano JSX

Another option is to use Nano JSX as shown in this example:

https://deno.com/deploy/docs/using-jsx

Nano SSR

Website in a single file

https://deno.com/blog/a-whole-website-in-a-single-js-file

https://deno.com/blog/a-whole-website-in-a-single-js-file-continued

This example uses nanossr, which is a tiny server-side renderer that uses Nano JSX with twind under the hood for styling.

ESM modules

https://esm.sh/

A fast, global content delivery network for NPM packages with ES Module format.

Deno 1.30 now has built-in Node modules.

node: URLs are supported as an alternative means to load Node.js builtin modules. This URL scheme allows for builtin modules to be referenced by valid absolute URL strings.

import { readFileSync } from "node:fs";

Installation

Installation docs

Add to PATH by editing .bashrc and add the two lines as mentioned when the installation finishes.

vi .bashrc

Check the verion

deno -V
deno --version

To upgrade:

deno upgrade

Extension: Deno for Visual Studio Code

Websockets

A multi-datacenter websockets-based chat, client+server in 23 lines of code on Deno Deploy. https://dash.deno.com/playground/mini-ws-chat

Explanation of the above code https://til.simonwillison.net/deno/annotated-deno-deploy-demo