What is Deno and should we start learning it?
A comparison with Node.js
You can install Deno in any one of the following methods (Link: https://deno.land/)
After installation you can start Deno by simply typing “Deno” from your command prompt
As we can see both Deno and Node opens an interactive prompt for performing calculations. But they can do more than that. Lets consider a simple Node.js code
The above code will display “Hello World!” in the browser, specifically on “http://localhost:3000/”. Also Node often works with packages like Express.js where we have to install the packages and maintain the package.json file to keep track of them. But lets see how Deno uses it
You can run Deno files using the command
Deno run "filename"
As you can see Deno supports TypeScript without the need of external compilation, instead the compiler is built into Deno. Now lets create a simple server with Deno just like in Node. I’ll use the same code provided in their documentation
We can see that Deno imports it’s modules not from any “node_modules” folder or through any built in imports instead it downloads the module directly from the link provided at the time of compilation and caches it locally so it need not download every time when we use that import again. Deno also allows top level awaits as in for plain promise functions, as opposed to Node.js which allows only Async level awaits. When you run the code you will face the following error
This is because, Deno promises a secure runtime where you can spin up a server only when you explicitly set the “- -allow-net” flag like this
Deno run --allow-net deno.ts
Where in Node.js you can spin up servers without any restrictions. This is a critical security feature in Deno which prevents third party libraries from compromising your system under the hood. This security feature is set by default restricting permission for network access and so on.
As a summary, Ryan tried to address the problems which he considered are regrets about Node.js . You can check out the entire video of his “10 Things I Regret About Node.js” here https://www.youtube.com/watch?v=M3BM9TB-8yA. He has successfully addressed quite some regrets he talked about like improved security, getting rid of node_modules and package.json and a new way to import modules.
Thank you and Happy learning!