# Is Deno the new Node?🦕


So In 2018, [Ryan Dahl](https://en.wikipedia.org/wiki/Ryan_Dahl)  (the creator of Node.js) issued “[10 Things I Regret About Node.js](https://www.youtube.com/watch?v=M3BM9TB-8yA)” in JSConf , He goes on including     several regrets about design he took over Node.js in 2009. Almost half of his talk, he showed us an experimental prototype called Deno successor of Nodejs which aimed to fix previous problems.

Deno  [v1.0](https://github.com/denoland/deno/releases) has launched and I think that it may be on the right track to replace Node.js in the future.

# **Deno**
**Deno** is a secure runtime for JavaScript and TypeScript. Imagine if you could write TypeScript without any config files, and bundle it all together into a single ES Module where both the TypeScript support and bundler are present in the core. That’s what it feels like when you get started with **Deno**.

It’s a modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. Whereas Node.js is written in C++ and JavaScript.

**Fun fact**: Deno is an anagram of Node. If you sort()  `node`  it becomes  `deno`🦕.

Deno ships with many features required for writing modern JavaScript & TypeScript, and WebAssembly code.
-   📦 bundler
-   🐛 debugger
-   🤖 test runner
-   🧶 code formatter
-   📖 docs generator
-   🧵 WebAssembly support


#### Deno has some interesting features

-   **Secure by default.**  
    No file, network, or environment access, unless explicitly enabled.
-   **Single Executable.**  
	Ships only a single executable file.
-	**TypeScript Support**
	Deno ships with out of the box TypeScript compiler.
-  **Module system**
	No  `package.json`, no  `node_modules`. Source files can be imported using a relative path, an absolute path or a fully qualified URL of a source file:
```sh
  import { test } from "https://unpkg.com/deno_testing@0.0.5/testing.ts"  
  import { log } from "./util.ts"
```
 
#### **What are the main issues with Node.js?**

- **Any program can write to the filesystem and the network**
	This might be a security problem, especially when intalling untrusted packages from npm.  [The](https://blog.npmjs.org/post/163723642530/crossenv-malware-on-the-npm-registry) `[crossenv](https://blog.npmjs.org/post/163723642530/crossenv-malware-on-the-npm-registry)` [incident](https://blog.npmjs.org/post/163723642530/crossenv-malware-on-the-npm-registry)  is an example. If  `crossenv`had not had writing permissions, this would not have happened.

- **The build system (GYP)**
	Using GYP to build a module that links to a C library is a big pain. In order to have a sane DX you’ll have to use  `node-gyp`  (a layer on top of GYP) and maybe other layers (like  `[nan](https://www.npmjs.com/package/nan)`).

- **The module system and npm**
	The main problem here is that the module system isn’t compatible with browsers so our code isn’t fully isomorphic. This is mainly caused by two reasons: storing dependencies in  `node_modules`  and having a  `package.json`.


# **Let's get started with installing Deno**

Using PowerShell (Windows):

```sh
iwr https://deno.land/x/install/install.ps1 -useb | iex
```
With Shell:

```bash
curl -fsSL https://deno.land/x/install/install.sh | sh
```

With Homebrew:

```bash
brew install deno
```

Now check if  `deno`  was installed by running the  `deno --version`  command in your terminal.

# **Simple http server**
This example contains a simple http server  (app.ts):

```sh
 import  { serve }  from  "https://deno.land/std@0.50.0/http/server.ts";
 const s =  serve({ port:  8000  });
 console.log("http://localhost:8000/");
 for  await  (const req of s)  {
	req.respond({ body:  "Hello World\n"  });
 }
```

Run the code:

```bash
 deno run app.ts
```

This results into permission error
```sh
 error: Uncaught PermissionDenied: read access to "http/server.ts", run  again with the --allow-read flag

 ► $deno$/dispatch_json.ts:40:11
 at DenoError ($deno$/errors.ts:20:5)
 ...
```
This is because deno allows you to control the granularity of permissions. To run above  application you need set some flags indicating deno that particular permission are allowed. 

```sh
 deno run --allow-net app.ts
 > http://localhost:8000/
```
Now open up your browser at localhost:8000. You will be see the **Hello World** text.
Okay this was just a basic demonstration of how you could create simple http server using deno. 

> See more example [here](https://deno.land/std/examples)

I  have created User REST API in deno feel free to check it out  [here](https://github.com/smithg09/Deno_REST_API). Clone the Repo and play around. Contribution are always welcome🎉

# Conclusion

There's still a long time until Deno reaches a production-ready state, but I think it’s on the right path in order to be a better Javascript runtime than Node.js🔥.
Thanks for reading! 👋👋

**Do check my website [smithgajjar.dev](https://smithgajjar.dev) and GitHub [here](https://github.com/smithg09)**
**Follow me on [LinkedIn](https://www.linkedin.com/in/smith-gajjar-5a27716b/)**

%%[buymeacoffee]
