BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News QCon SF 2023: Streamlining Cloud Development with Deno by Ryan Dahl

QCon SF 2023: Streamlining Cloud Development with Deno by Ryan Dahl

Ryan Dahl, Co-Founder and CEO at Deno and Software Engineer best known for creating Node.js, presented Streamlining Cloud Development with Deno at the 2023 QCon San Francisco conference.

According to Dahl, the web has become the medium of human information. It should exist five years from now and perhaps even the next 10 or 20 years. JavaScript is inherently tied to the web and therefore, JavaScript will be important in the future.

As the creator of Node.js, Dahl's goal was to enable developers to easily build fast servers by only exposing asynchronous I/O in JavaScript. However, building those fast servers requires more than just asynchronous I/O.

Issues that need to be addressed included: managing complex cloud configurations; some sort of geographically replicated state; navigating a plethora of software, workflows and toolchains; and supply chain security. This was his inspiration behind creating Deno, an open source next-generation JavaScript runtime that is: secure by default; offers native support for JavaScript and TypeScript; ships with testing, linting, formatting and more; is backwards compatible with Node.js and npm; and contains web standard APIs.

Deno is a single executable file that is 100MB large and has support for 14 different web standards, such as: globalThis, window.close(), FormData and webAssembly. Deno is also a browser for command-line scripts, as shown in the following examples:

    
$ deno run https://deno.land/std@0.150.0/examples/gist.ts
    

The above Deno command will upload a Gist file to GitHub.

    
$ deno run npm:cowsay moo
    

The above Deno will execute an npm application named cowsay and display ASCII art of a cow saying "moo."

Once installed, Deno can initialize a project using:

    
$ deno init
    

It will generate three files, main.ts, the main application that defines a function to add two numbers and display it on the terminal window; main_test.ts, a simple test for main.ts; and deno.json, a JSON file that defines the deno run command. The main application and test are executed as follows:

    
$ deno run main.ts
$ deno test main_test.ts
    

Dahl then provided a demo on how to quickly build an asynchronous compression stream application in only three lines of code, as shown in the following example:

    
const src = await Deno.open("/etc/passwd");
const dst = await Deno.open("out.gz", {write: true, create: true})
src.readable.pipeThrough(new CompressionStream("gzip")).pipeTo(dst.writable);
    

Upon executing the above application, Deno requested read access and write access to the file to be opened and the gzip file, respectively.

Libraries from Node.js can be imported into Deno applications, as the following example shows:

    
import { readFileSync } from "node:fs";

const etc = readFileSync("/etc/password");
console.log(etc);
    

It is important to note that Deno security permissions still apply when importing libraries.

Deno Node Transform (DNT), a Deno-to-npm package build tool that can transpile JavaScript for distribution on npm. Deno tests can also be transpile and executed on Node.js. Dahl provided a demo on how to build an Express server:

    
import express from "npm:express"

const app = express();
app.get("/", (_req, res) => { res.send('Hello\n');});
app.listen(3000, () => { console.log("server on http://localhost:3000"); });
    

Deno Deploy, the "easiest serverless platform," as Dahl claimed, features: scaling to zero cost; support for npm packages; built-in storage and compute; low global latency in 35 regions; fast cold starts; and powers Netlify Edge functions. To install Deno Deploy, simply execute the following command:

    
$ deno install -Arf https://deno.land/x/deploy/deployctl.ts
    

Deploying applications is accomplished with the deployctl command as shown in the following example:

    
$ deployctl deploy --project=hello-world ./examples/hello.ts
    

It is important to note that a personal access token is required before using Deno Deploy. One can be obtained from the access token page. The token may be stored in the DENO_DEPLOY_TOKEN environment variable or passed into the deployctl command with the --token flag.

Dahl then provided a demo on taking the aforementioned freshly-built Express server and deploying it to the cloud.

Deno KV, a datastore anchored by ACID transactions and powered by FoundationDB. Features include: zero configuration; ACID transactions; scaling to zero cost; and built-in Deno Deploy. Dahl stated that Deno KV doesn't replace a real database, but it is useful for sharing state.

About the Author

Rate this Article

Adoption
Style

BT