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
Run Javascript on the server!
Tired of having a fast and secure server environment? We have the solution!
Make sure to use proprietary module loading formats for extra confusion!
const fs =require("fs");// What is this?
Cross-compatibility? What’s that? We load weird binaries constantly with .node
files!
:node_modules:
That was dumb
Run, Bundle, and Compile Typescript (or Javascript).
Security is built-in. Everything is sandboxed.
Uses official ECMAscript syntax for imports.
WebAssembly for modules with speed (no proprietary formats)
Caches all modules in one centralized location. No more gigabytes of downloads
per project.
Install
Installing Deno does not require a custom installer because it’s literally
just one executable.
Quick Install Script:
curl -fsSL https://deno.land/x/install/install.sh | sh
Breakdown (for those of us who aren't linux experts):
curl: download script from URL
|: pipe the output to the next program
sh: run a bash script
Overview
Deno namespace
If you want to do something closer to system-level, Deno provides a number of
APIs through the “Deno” namespace
Deno.env.get("TMPDIR");// get environment variable
Deno built-in library
Deno, unlike Node does not treat built-in modules any differently than
anything else.
Deno does provide modules built by the team publicly but it is referred to as
the “Standard Library” (presumably to make it more similar to other better
languages)
Use the deno lint and deno fmt commands to do this.
The defaults are pretty good, and are probably what you want anyways.
Personally, I always hated setting up eslint and finding which rules I liked
best.
Customizable with the deno.json file.
Bundling in Deno
Guess what? It’s built in.
NO MORE WEBPACK!
Just run deno bundle
By default this will just output the result in stdout, you can specify a
file name if you want it to be saved. Otherwise, you could pipe the result
somewhere else (maybe to something like babel).
Compiling in Deno
What?
You can compile your Deno utilities straight down to an executable. This is
more of a cool feature than something particularly useful but why not
Common Doubts
“Cool, but useless with an Ecosystem”
Usually this would be a big concern for a new runtime since usually it implies
a new language.
Deno just runs typescript (or javascript), the code is already out there!
You want to use a node module in deno? You have two options:
Skypack
Allows you to import basically all ESM node modules just like any other
file!
DNT
A command-line tool that allows you to transform a node module into a deno
module by some magic and inserting shims when necessary
If you prefer the workflow of Deno, NOTHING IS STOPPING YOU FROM USING IT NOW
“It doesn’t really run Typescript, it’s lying”
This is fundamentally just nitpicking but I’ll elaborate anyways. I think
quoting the manual explains it best.
“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”
Deno uses a combination of TSC and SWC to translate your code to javascript in
real time.
Tip: Type checking can be slow, so if you want to avoid waiting you could
just use the --no-check flag in dev and remove it for tests in prod.
“Okay but I use X obscure feature with Typescript. Now what?”
You can configure Typescript using a tsconfig file like any other system.
Tip: You can also use deno.json to customize your typescript!
“How is the module resolution any better than Node”
This is mostly a matter of perspective. “Better” is a judgement.
In my opinion, URL imports are a significantly better idea for any developer
who supports freedom because it removes the need for centralized package
managers.
Package managers do exist if you really want them, but personally I do not
recommend using them with Deno
You don’t need to download the module every time you need it. If it’s the same
module as before, why waste your precious disk space.
The lock file REALLY is a lock file with no magic upgrading of modules.
“URL imports are bad because what if host server goes down”
True.
How is this any different than NPM? Or Rust Crates? Or literally anything on
the internet?
You can mitigate the dangers of this by using some stuff we’ve already talked
about
Use a lock file. Make sure that if the web-server somehow gets hacked,
you’ll be fine.
Mission-critical programs already have a solution to this. You have two
options:
Bundle your program using built-in tools to remove need for this
Simply put the modules in your version control. Yes, Deno does support this.
“I miss my package.json because I want my npm scripts”
Deno has a configuration file (which should be named deno.json or deno.json5)
that allows for a ton of tweaking with options.
You explicitly do NOT need it. Everything that you could want to do can be
done by passing in arguments
Deno.json has a “task” system very similar to npm scripts. Just run
deno task x
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.