Getting started with Deno

Article by: Chris Kettenbach

As its web site says, Deno is a simple, modern, and secure TypeScript and JavaScript runtime that uses Chrome’s V8 JavaScript engine. It’s built using the Rust programming language, in contrast with Node.js, which is built using C and C++. It’s from the creator of Node, Ryan Dahl. Notice that Deno is an anagram of the word “node” … perhaps hinting at rearranging or fixing parts of Node? Both platforms are open source.

Why should I learn Deno?

TypeScript is a first-class citizen, and most new JavaScript applications are written in TypeScript. This includes React, Angular, Node.js, and Express.js applications, and the list goes on and on. Also, most classic libraries are either ported to TypeScript or @types provided by third parties, the reason being that developers and customers want to take full advantage of the rich tooling TypeScript brings to a project.

Variables and Functions are strongly typed, which catches many coding errors long before they see the light of production. Variables aren’t left undefined or changed sporadically throughout the application lifecycle. This makes for much more reliable, predictable applications.

Other reasons include vastly improved security over Node as well many features out of the box that you can add in a traditional JavaScript application.

How is Deno different?

• No package.json file

• No tsconfig.json file

• Dependency management

• The runtime is secure by default

Tsconfig.json is traditionally used to configure the typescript compiler (tsc). You can include a configuration file, but I find it is not generally needed. Deno enables the strict options by default — “NoImplicitAny,” “StrictNullChecking,” to name a couple.

There are also no “node_modules” directory and no package manager. Dependencies (other libraries required for the application) are imported directly into local modules. The fully qualified URL/version and file extension are required.

This can quickly become cumbersome as the application grows. A standard practice in Deno is to create a deps.ts file. The idea is to import everything in one place and re-export. Then local modules only need to reference the deps.ts file and the functions they need.

Versioning is maintained in user created lock.json file. The filename and version info are hashed in this file.

Fetch web api is also included in the Deno runtime. Node requires third-party modules for http callouts.

How do I install Deno?

Using Shell (macOS and Linux): curl -fsSL | s

Using Powershell (Windows): iwr -useb | iex

To test your installation, run deno --version. If this prints the Deno version to the console, the installation was successful.

Which tools do I need?

I use Visual Studio Code and the official Deno extension. If you search the VSCode extension gallery for Deno, you’ll quickly find it. I have included a link below, under “Links and resources.” One small “gotcha” is that you need to go into the workspace settings file and enable the plug-in.

What are some advantages to using Deno?

• It adds on existing developer experience, and it’s familiar to front end and backend. Developers can leverage TypeScript and JavaScript knowledge.

• Teams using a unified developer platform. Both front-end and backend code can be developed by the same teams, with no silo development. Everyone is coding in the same language. Obviously this also promotes code reuse.

• Rapid API/prototyping delivery. Proof-of-concepts can quickly be created and demo’ed to stakeholders. Very fast time development cycles.

Final thoughts

I do feel it was a major win to have TypeScript supported and to use Rust to build it. I think startups and smaller companies will be the earlier adopters and that in time, larger enterprises will come on board. This was also true at one time about Node. No big industry took it seriously, and now it’s basically everywhere. I see Deno eventually in that same space. These are of course just my opinions.

Bottom line, give Deno a try. I think you’ll really like it.

Links and resources

Enabling clarity through business and technology solutions.