A Quick Guide to Deno

I've been using Deno for a while now and I am really enjoying it.

This article is actually created based on a talk I did, so just keep that in mind for context.

The Folly of Man

Why NodeJS is terrible

const fs = require("fs"); // What is this?

That was dumb

Install

Quick Install Script:

curl -fsSL https://deno.land/x/install/install.sh | sh

Breakdown (for those of us who aren't linux experts):

Overview

Deno namespace

Deno.env.get("TMPDIR"); // get environment variable

Deno built-in library

Deno module resolution

import { Application } from "https://deno.land/x/oak/mod.ts";
// lock.json
{
  "https://deno.land/std@0.139.0/textproto/mod.ts": "3118d7a42c03c242c5a49c2ad91c8396110e14acca1324e7aaefd31a999b71a4",

  "https://deno.land/std@0.139.0/io/util.ts": "ae133d310a0fdcf298cea7bc09a599c49acb616d34e148e263bcb02976f80dee",

  "https://deno.land/std@0.139.0/async/delay.ts": "35957d585a6e3dd87706858fb1d6b551cb278271b03f52c5a2cb70e65e00c26a"
}

Okay but how do I use them in my code?

“URL imports are a nightmare for version control” - Matt Two main methods

// dep.ts
export { Application } from "https://deno.land/x/oak/mod.ts";

// main.ts
import { Application } from "./dep.ts";
// ...
// import_map.jsonc
{
    "imports": {
        "oak/": "https://deno.land/x/oak/"
    }
}

// main.ts
import { Application } from 'oak/mod.ts'
// ...

Quick Note: In both cases you would want to version your module:

import { Application } from "https://deno.land/x/oak@10.5.1/";

Testing in Deno

No more third-party frameworks for testing!!!

import { assertEquals } from "https://deno.land/std@0.140.0/testing/asserts.ts";

Deno.test(() => {
  assertEquals("monkey", "monkey"); // success!
});

Linting/Formatting in Deno

It’s built in. Finally.

Bundling in Deno

Guess what? It’s built in.

Compiling in Deno

What?

Common Doubts

“Cool, but useless with an Ecosystem”

“It doesn’t really run Typescript, it’s lying”

“But wait a minute, does Deno really run TypeScript? you might be asking yourself. Well, depends on what you mean by run. One could argue that in a browser you don't actually run JavaScript either. The JavaScript engine in the browser translates the JavaScript to a series of operation codes, which it then executes in a sandbox”

“Okay but I use X obscure feature with Typescript. Now what?”

“How is the module resolution any better than Node”

“URL imports are bad because what if host server goes down”

“I miss my package.json because I want my npm scripts”

{
 "tasks": {
   "test": "deno test",
   "giveup": "rm -rf /*”
 }
}

Conclusion

I believe that Deno has a good chance of making it big, especially in enterprise with it's focus on security, reliability, and customer support. While I don't think Deno will ever really replace Node, I truly think it has a good shot of being a popular alternative.

If you have different opinions, let me know! I'd love to have a dialogue and hear your perspective.

If you're interested in more from me, subscribe to my blog! I post like twice a month so honestly it's not going to fill your inbox.

Comments