Why Deno?

Deno Typescript

Instead of Python or Node I find myself reaching for Deno whenever I need a script, a server, or a CLI. I keep wanting to use Golang more but always end up circling back to Deno. It's easy to use and I feel productive with it. Their docs are great too!

What is Deno?


Deno is a Javascript runtime created in 2018 by Ryan Dahl the original creator of Node.js. With Deno 1.0 version released in 2020. You'll notice Deno is an anagram of Node. It's a Javascript runtime built with Rust with a standard library that is similar to Go's. He created it to fix shortcomings in Node.js. See the announcement talk here.

Excellent DX


Built-in Testing, Linting, and Formatting

It may seem trivial but this is one of my favorite features. Modern languages like Rust and Golang have these built-in which is a huge productivity boost. A lot of times projects won't have this at all or it leads to bike-shedding.

When working on a project for more than one developer formatting linting and formatting is a must. It cuts down on a lot of noise in code reviews. You can format your code with deno fmt and lint with deno lint. There's also an official VSCode extension that will do this on save for you.

Deno's built in testing is robust and easy to use. It even has a watch mode. You can run tests with deno test.

It also has a deno bench for benchmarking.

TypeScript: first class support

Deno has zero config TS. It has first class support for Typescript so you can write your code in TS without any additional setup.

Secure by default

You have to explicitly give permissions to scripts to access the network, file system, and environment. Node apps and their dependencies have access to everything by default. It's fairly easy to do this with command line flags. For example, deno run --allow-net script.ts.

ES modules and imports by URL

It uses ES modules so no more CommonJS require statements. Node uses CommonJS and now also supports ES modules. ES modules are the standard. Imports in Node could be confusing since they also could use AMD. This is a great deep dive into ES modules. Here's an interesting screed on CommonJS and it's history.

One of the main differences between Deno and Node is that Deno imports modules by URL which is also how Go does. So no NPM although it's still possible to use NPM packages. Recently the Deno team has released JavaScript Registry (JSR). A package manager for JS and TS that is a superset of NPM.

Modules are also locally cached. So it's fast and possible to work offline.

Standard Library

Deno has a useful built-in standard library. You don't have to install additional packages for basic functionality. This helps with the problem if node_modules getting huge. Take a look at the collections module to see how powerful it is. Beyond the standard library Deno has a lot built-in. Projects usually end up with few dependencies.

Deno compile

It's easy to make an executable with deno compile [--output <OUT>] <SRC>. It also allows for cross-compilation.


All of the above lead to a consistency in Deno projects that is lacking in Node. Node projects I've worked sometimes had a lot of spaghetti code and bespoke setups. Node requires a lot of configuration and additional packages which all add complexity. Say good bye to the loads of config files!

Getting started with Deno


Just head over to their website and dive in.

If you're curious about specific use cases such as reading a file they have a handy Deno by example section. I use Deno primarily for CLIs to process data from files and APIs. Here's a basic tutorial of building a CLI with Deno.

Conclusion


I'm excited to keep working with Deno and use it for more complex projects. I wouldn't hesitate to use it for critical applications. I really like that they fixed shortcomings of Node and took inspiration from good parts of other technologies such as Go and Kotlin. It's really great to not have to fiddle with a bunch of configs before diving into a project or if you're just writing a quick script.

I have some ideas in mind to try out their deploy service and their web framework Fresh. I'll be sure to write about my experiences with them.