There are several differences between the two, but in this article we will focus on three of them: Integrated typescript support, security and package management.
Installation is very simple and can be performed from the command line.
For macOS and Linux:
curl -fsSL https://deno.land/x/install/install.sh | sh
And for Windows, using Powershell:
iwr https://deno.land/x/install/install.ps1 -useb | iex
That’s it, now you can run your first program using Deno like this:
deno run https://deno.land/std/examples/welcome.ts
As you can see, you can just provide an url of the file without having the source code on your machine.
You can read more on installation information here.
Integrated Typescript support
deno run main.ts
It’s that simple. No more transpilers.
Deno is more focused on security. By default, a program has no permissions (file, network and others) and you need to grant them when you run the code from the command line.
Some of them are:
–allow-net=<allow-net>. You can allow all network calls or specify allowed domains (i.e. –allow-net=github.com,gitlab.com)
–allow-read and –allow-write are similar and like the previous one, you can allow access to any file or specify allowed folders or files (–allow-read=/etc)
A list with all the permissions can be found here.
In the beginning of the article you’ve seen that you can execute a file using just an url. That applies also to dependencies since we no longer have node_modules and package.json like we did with Node.js.
Using a third party library is not always as easy as it should be, but with some luck you may find your desired module on https://deno.land/x and import it like this:
import format from “https://firstname.lastname@example.org/format/index.js”
Let’s get our hands dirty and run some piece of code using Deno. Here’s a simple utility script that looks for duplicates in a list of folders. You can run it like this:
deno run --allow-read --unstable "https://bit.ly/C4N-checkDuplicates" folder1 folder2
You may also delete the duplicates using the –delete / -d flag:
deno run --allow-read --allow-write --unstable "https://bit.ly/C4N-checkDuplicates" folder1 folder2 -d
Note that the –allow-write permission was granted so the files can be deleted. Otherwise an error is raised.
As of October 2020, more than two years after the first release, Deno reached version 1.4.4 and it begins to be considered production ready. If you’re not comfortable to use it in your project right now, it would be useful to get to know the new kid in town since you might use it in the near future. Until then, you can start using it instead of bash or python for writing utility scripts.