In 13th May 2020, finally Deno is out, after two years of its first release.
For all the years of my career always I heard about the end of one or the other programing language or technology. So it was with Delphi, also PHP, within others. More recently it was the turn of the Node.Js.
One day, maybe every programming language will die (I'm not sure ...), but I really don't believe in the death of Node.js. At least not now.
But, what is Deno?
As written in the Deno documentation, it is a secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. You can see more details in https://deno.land.
Basically, Deno is a program for running JavaScript and TypeScript code outside of a browser, just like the Node.
Deno was created by Ryan Dahl, the same creator of Node, but now with focus in security and productivity. It was announced by Dahl in 2018 during his talk "10 Things I Regret About Node.js" at JSConf EU that year.
Introduction to Deno Features
First, to start, we need to install Deno and this task is very easy for any operating system. See more at https://deno.land/#installation.
Deno is a command-line program. After its installation, you can get using the following commands to help you start works with it.
$ deno help
$ deno --h
$ deno --help
To launch a Deno app you need simply use at the command line:
$ deno run <entry-point>
This entry point can be a JavaScript (.js) file or TypeScript (.ts) file. But the great news is the possibility to use a URL that points to an app entry point.
Deno’s website provides some examples, like these.
Let’s run it to see what happens.
$ deno run https://deno.land/std/examples/welcome.ts
Download https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕
Deno downloaded the welcome.ts
file, and compiled it, and ran it. If we run the app again, Deno will just run it, because it’s cached by Deno.
$ deno run https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕
Deno downloads all the modules and caches them. It will not download them again until you specifically request them with the reload flag
.
$ deno run --reload https://deno.land/std/examples/welcome.ts
Download https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno 🦕
And the best so far is that when Deno runs the app, it only compiled the TypeScript file, that is, we don’t need to use any transpiler for that.
It happens because Deno supports Typescript out of the box.
EcmaScript modules vs. CommonJS
Deno uses the last ECMAScript features in its API and libraries and because of the native support of ES Modules in Deno you don’t have to use other build tools to make your application ready to use in a browser.
Deno supports ES Modules, instead of the CommonJS syntax used by Node. As a result, dependency management is very simple and flexible and it just uses a local or remote URL, but it provides compatibility with Node too.
For example, require functions (require()
) is not supported. The ES Modules standard syntax uses the import statement for that (import defaultExport from "module-name"
).
To load CommonJS modules you can use createRequire(...)
, like the example below.
import { createRequire } from "https://deno.land/std/node/module.ts";
const require = createRequire(import.meta.url);
// Loads native module polyfill.
const path = require("path");
// Loads extensionless module.
const cjsModule = require("./my_mod");
// Visits node_modules.
const leftPad = require("left-pad");
More details about that and examples like this can be seen at the link https://deno.land/std/node.
As we saw earlier, we can use a URL as an entry point to run a Deno application. And as we can also use a local or remote URL to manage the dependencies I created a repository on GitHub to send some examples from Deno and I can simply import dependencies from there.
I simply created a file called hello.ts
that imports a welcome.ts function that prints the same standard greeting message that we used in the previous examples.
Let's see below the content of hello.ts
.
import { welcome } from 'https://github.com/jaquiel/deno-features/raw/master/std/welcome.ts'
welcome()
Now, the result of running the app.
$ deno run hello.ts
Compile file:///C:/Users/jaquiel/Documents/vscode/deno/deno-features/std/hello.ts
Download https://github.com/jaquiel/deno-features/raw/master/std/welcome.ts
Download https://raw.githubusercontent.com/jaquiel/deno-features/master/std/welcome.ts
Welcome to Deno 🦕
It's really very easy and simple to work with Deno.
Security
As previously seen, in Deno's own documentation it is defined as a secure runtime for JavaScript and TypeScript. To access to security-sensitive areas or functions, you must use permissions on the command line.
Let's see an example of the Deno website.
Running without using the --allow-net
flag we will get the following result.
$ deno run https://deno.land/std/examples/echo_server.ts
error: Uncaught PermissionDenied: network access to "0.0.0.0:8080", run again with the --allow-net flag
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
at Object.listen ($deno$/ops/net.ts:51:10)
at Object.listen ($deno$/net.ts:152:22)
at https://deno.land/std/examples/echo_server.ts:4:23
We can see that we had a permission denied error. But if we use the flag the app will run without any problem.
$ deno run --allow-net https://deno.land/std/examples/echo_server.ts
Listening on 0.0.0.0:8080
In the link https://deno.land/manual/getting_started/permissions#permissions-list , we can see the detailed list of all available permissions.
Conclusion
Well, my goal wasn’t to explain Deno's features to you, because the documentation can help you understand it easily. Rather, I just wanted to try these advantages in practice.
I reiterate my opinion that Node.js will not die and will not be replaced by Deno, because it is a well-established technology that will certainly remain for many years and, in addition, its own creator developed Deno only as an alternative to Node, and not as a replacement.
Finally, although I believe in a long life for Node I can't help saying that the new Deno’s features are truly exciting and it is, likely, the new Hype.
Top comments (19)
Other predictions of the past.
Microsoft saying they would kill the mainframe.
Java would replace everything.
C++ was better than chewing gum.
C# would kill Java.
But, Cobol is still kicking after 50 years.
As for Deno, I think it's architecture looks great. Its on my radar , but until the market appears I'm not going to stress out on learning it.
The good news is that other frameworks like Angular etc. already incorporate the module system. This means that ramp up time should be small.
You left one. Javascript will take over the world as Python did
Good thinking! Thanks!
Very good observations on old predictions.
And really, Cobol is a great example of a long life. Impressive!
Thanks for sharing.
Let me add another...
Well said: "it is, likely, the new Hype" ... that's what it is, a hype. Just wondering, if ever a future node.js version would support TS compilation and EcmaScript modules, then what would still be the advantages of Deno? The differences would become pretty marginal.
Yes, I agree with you!
Whenever a new hype arises, it also brings a lot of expectations.
Deno is really interesting and brings a lot of news, but his future is certainly still unknown.
Deno's future may be very promising, but it will depend on many factors, including what you mentioned about the Node that is already consolidated.
Well, if Node was dead I guess that Deno wouldn't have used it for its website
Not really worth the time to build your own web deployment solution when you can focus on actual engineering for your newly GA'ed product.
twitter.com/luke_pighetti/status/1...
I can't agree more, not using Deno is a sensible engineering decision
It's a good point!
I think the question shouldn't be: is node dead? Or even: is deno going to kill node?
We all know about picking the right tool for the job, this is just another tool that will fit some job. Which is great. The more tools we have, the more we can mix and match to suit our needs!
Good idea!
Certainly, your suggestion would have been a good question for the title of this article.
Thank you for your cooperation.
I think Deno will definitely replace Node when it comes to running JavaScript applications on a server, as the developer experience is so much nicer. But Deno is a long way off replacing Node in terms of browser support, and it may never do so. So I think we can expect Node to be around for the foreseeable future.
Deno will produce some new stories!
But it can't override the nodejs stories...
I agree. I hope both produce good stories!
Thanks for your comment.
As the world moves towards API Gateways and Lambda / Functions I see less need for many of the features Dino / Node provides. Many of the services provided by a framework will inevitably be pushed outside the endpoint.
I don't think Deno would kill Node Js but It would be interesting to see how community and enterprise adopt Deno
In fact, I'm also looking forward to seeing what the adoption of Deno will look like.