DEV Community

Cover image for 🦕Deno the Node replacement? Bonus: I created a boilerplate for Deno
Michael "lampe" Lazarski
Michael "lampe" Lazarski

Posted on

🦕Deno the Node replacement? Bonus: I created a boilerplate for Deno

First things first

Deno is right now not production-ready. As of writing this post, it is in version 1.0.0-rc2. Does this mean we should ignore it? No, we should start to learn it right now because it will maybe take 1 or 2 years but if nothing tragic will happen then it will replace Node or at least will be as popular as Node.

I'm not bashing Node here. I love Node and I think it helped so many people but at times it can also be slow to evolve. Like adding module support and adopting ECMAScript(javascript) standards.

Also, NPM can be a mess but to be fair dependency management, in general, is not easy. Also tooling around node can be hard to setup. Like webpack or eslint/prettier. I'm always using some kind of boilerplate that does not work anymore because of so many updates. Okay, enough about Node/Npm.

What is Deno?

According to the Deno website:

A secure runtime for JavaScript and TypeScript
Okay, so what we know is that we can run Javascript and Typescript on bare metal.

Dinging a little bit more into the documentation we can find the following information.
One of them being Deno is secure by default. But what does that mean?
By default Deno runs in a sandbox without any access to the system. Actually you have to specify what your Deno project can access and whatnot. This alone is amazing. So if some dependency wants to access your filesystem which it should not it simply can't.

Node is written in C++ which at the time it was developt was the best choice. Since then we go some easier and secure languages like Rust. This is why Deno is written in Rust. Rust is an amazing language that also supports Webassambly. It is also secure by default.

Some other cool things are that Deno comes with Typescript support ot of the box, It can be bundled into a single file and has a build-in test and code format solution. It also has a built-in package manager. So to start quickly or just to try some things you don't need much! just Deno.

If you want to know more about the differences you can read them here

Creating our boilerplate

Installing Deno is easy:

#Unix
curl -fsSL https://deno.land/x/install/install.sh | sh

Now you should have the deno command at your fingertips. In general, I would advise you to use a Unix-like OS. If you are using Windows then you can use WSL.
Also, you should have git installed and make.
You can clone the boilerplate code like this:

git clone https://github.com/lampewebdev/deno-boilerplate

For this tutorial, I will use VS code and you should download the Deno VS Code Extension

If you open the project in VS Code you can see the following files:
Alt Text

Let us try to understand the most important files.
The .vscode folder contains a settings.json file where we need to enable Deno.

{
    "deno.enable": true
}

The next file we should have a look at is the makefile.
You can see the following commands in the makefile:

  • make run: executes the index.ts
  • make test: runs the tests
  • make format: formats all your files
  • make debug: runs the debugger starting in the index.ts
  • make bundle: bundles your project into a single file in build/index

For all these commands we don't need any extra tools or dependencies. It's all built-in Deno. I find this great and it makes your life as a developer so much easier. On thing I wish was in Deno by default would be a --watch flag that reruns your code once a file has changed.

Another interesting file is the deps.ts file. This is just a normal Typescript file but by convention, this file is where you organize your external modules/packages you are using.

import * as Log from "https://deno.land/std/log/mod.ts";

export {
  Log,
};

This is the deps.ts. Think about it like your package.json.
It is a central place where you store your dependencies. One thing that will be interesting to see where development dependencies should go. I have seen people doing dev-deps.ts. I would prefer deps.<ENV>.ts. So for example deps.prod.ts, deps.dev.ts and so on.

The configs.ts for now is empty. I like dotenv files but we will see what wins in Deno.

then we have the index.ts. It is our entry point and as a web developer I like index but I would also have no problem to rename it.

The rest is pretty standard stuff.

We have a main.ts where we can start to implement things and an example of how to implement the simplest logger in Deno.

What I want to add are tests and documentation. Both are built-in Deno and you need no extra tools.

If you want to help just contact me or create an issue or pull request in the GitHub Repo

Would you like to see more Deno content? Please let me know! I would like to make more posts and content about Deno!

👋Say Hello! Instagram | Twitter | LinkedIn | Medium | Twitch | YouTube

Top comments (19)

Collapse
 
louy2 profile image
Yufan Lou

For all these commands we don't need any extra tools or dependencies.

You used make. The proliferation of build tools in Node.js is partly driven by the absence of make on Windows. Deno has drake.

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

make is just a nicer way of typing the commands all the time. This is also why I wrote that on windows you should use WSL.

I know about drake.

For now, I want to use much 3rd party libs because they first need to prove that they will be maintained for a longer time.

Collapse
 
louy2 profile image
Yufan Lou

Ah sorry I missed the WSL part.

Thread Thread
 
lampewebdev profile image
Michael "lampe" Lazarski

No problem :)

But yeah at some point maybe make is not the best solution :)

Collapse
 
harken24 profile image
Jozo

I'm having issue when i run make in my terminal I get error error TS2339: Property 'size' does not exist on type 'FileInfo'.
Not sure if'm doing something wrong or what?

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

What OS?
What terminal bash/zsh/fish?
What is the output of deno -v ?

Collapse
 
harken24 profile image
Jozo

OS is debian 10 (buster)
terminal is terminator and shell is zsh extended with oh my zsh
output is deno 0.36.0

Thread Thread
 
lampewebdev profile image
Michael "lampe" Lazarski

Can you try:

deno upgrade --version 1.0.0

and then run it again ?

Collapse
 
sirseanofloxley profile image
Sean Allin Newell

Thanks for the VSCode extension link and boilerplate repo! This was the missing piece for making all my 'smart scripts' (beyond bash) I like to write occassionally migrate to deno.

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

If you have any suggestions how to make the boilerplate better please feel free to write me 😊🙌

Collapse
 
pandaquests profile image
Panda Quests

Are you the owner or an contributor of Deno?

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

No, the owner/creator is the same as Node.

I'm not yet a contributor but I'm looking into it.

Collapse
 
barzi92367868 profile image
Barzi

Thank you for your article.
Are you planning to write more about deno? I'm looking forward to reading more about it.
Tonight I'm going to give Deno a try myself.

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

Thank you for reading it :)
Depends a little bit if people are interested in that topic :D
But I would love too

Collapse
 
alexandrudanpop profile image
Alexandru-Dan Pop

Really like the deps.ts convention!
I wonder if this will stick and really become a standard because otherwise it will be really hard to track all the deps in Deno.

Collapse
 
maheshkale profile image
Mahesh K

I have one question: Is deno specifically pushing for typescript? Or we are free to focus on vanilla javascript?

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

They use typescript in the repo but you can use both.

Collapse
 
jsn1nj4 profile image
Elliot Derhay

Awesome, thanks! Will give this a try when I toy with Deno for the first time.

Collapse
 
lampewebdev profile image
Michael "lampe" Lazarski

Have fun with deno 👍😊