🦕Deno the Node replacement? Bonus: I created a boilerplate for Deno
Tags: deno, node, typescript, javascript
Published: 2020-05-10 17:20:20

## 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](https://github.com/denoland/deno/blob/master/docs/introduction.md)

## Creating our boilerplate

Installing Deno is easy:
```bash
#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:
```bash
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](https://marketplace.visualstudio.com/items?itemName=axetroy.vscode-deno)

If you open the project in VS Code you can see the following files:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zjl1jyi6lrrbv931hkph.png)

Let us try to understand the most important files.
The `.vscode` folder contains a `settings.json` file where we need to enable Deno.
```json
{
    "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.

```ts
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](https://github.com/lampewebdev/deno-boilerplate)

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](https://www.instagram.com/lampewebdev/) | [Twitter](https://twitter.com/lampewebdev) | [LinkedIn](https://www.linkedin.com/in/michael-lazarski-25725a87) | [Medium](https://medium.com/@lampewebdevelopment) | [Twitch](https://dev.to/twitch_live_streams/lampewebdev) | [YouTube](https://www.youtube.com/channel/UCYCe4Cnracnq91J0CgoyKAQ)