Last Updated On By Khizer Ali
Deno is an emerging technology and is rising through the trends. Deno gained popularity because of its unignorable features and improved alternatives to node js.
In this article, we will go through on how deno claims to be better than node js with the help of coding examples.
The new features that deno introduced are the following
deno is built on Rust and typescript, another set of powerful technologies. It also uses a v8 chromium engine. Whereas, node was written in C++ and javascript.
there are multiple ways in which you can install deno
Shell (Mac, Linux):
curl -fsSL https://deno.land/x/install/install.sh | sh
PowerShell (Windows):
iwr https://deno.land/x/install/install.ps1 -useb | iex
Homebrew (Mac):
brew install deno
Chocolatey (Windows):
choco install deno
Scoop (Windows):
scoop install deno
Cargo
cargo install deno
now you can try and run the following command and you will run the script from the deno land from the internet
deno run https://deno.land/std/examples/welcome.ts
you can run deno through the command line just like node js
Let’s write code of our own instead of running someone else’s code through the URL.
import {serve} from "https://deno.land/[email protected]/http/server.ts";
const s = serve({ port: 8080 });
console.log("http://localhost:8080/");
for await (const req of s) {
req.respond({ body: "Welcome to Deno!\n" });
}
Now, this is the basic program that you can write. The first line imports from the URL and you don’t have to npm install anything every time.
Now once you try to run this program, you will get an error. Deno won’t allow you to run the program until you explicitly give permission.
Now run the following command to give access to your browser.
You can access the application through the localhost with an 8080 port.
Voila! You have your application running.
With these codes as examples, there won’t be much need of formatting your code but when the codes start to grow, it can get messy. you can run the following command to format your code.
deno fmt index.ts
Note how a terminator is put where it was missing and the code has been formatted.
Let’s take a look at the above code!
the mod.ts file has been imported from the deno land for all the dependencies to enable hashing and encoding. The second line consoles the output by encoding “code leaks ” through sha1.
Output:
Deno is still growing over time and many developers are still working on improving deno more. Deno was intended to overcome the shortcomings of node js and add more impressive features.