Ryan Dahl the original creator of Node.js (the popular server-side JavaScript runtime) announced Deno at JSConf EU 2018 on is his talk titled "10 Things I Regret About Node.js" ( From the title you can see where are we heading to ). In another word, if you are familiar with Node.js then Deno is just like that. Except that it's improved in many ways, it's created from bottom to top to be a better implementation of Node.js. - By Vincent Mancini.
Since Deno and Node.js serve the same purpose, it's possible to compare the two directly.
Node | Deno | |
---|---|---|
Engine | V8 | V8 |
Written in | C++ & JavaScript | Rust & Typescript |
Package managing | Package managers: npm | Uses URLs |
Importing packages | CommonJS syntax | ES Modules |
Security | Full access | Permissioned access |
TypeScript support | Not built in | Built in |
Deno ships as a single executable with no dependencies. You can install it using the installers below.
- 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
Try running a simple program:
/home/<user>/.deno/bin/deno run https://deno.land/std/examples/welcome.ts
NOTE: the user it is your computer. In my example it is:
/home/filipe/.deno/bin/deno run https://deno.land/std/examples/welcome.ts
You can to verify the version of Deno:
/home/<user>/.deno/bin/deno --version
The expected output:
deno 1.1.0
v8 8.4.300
typescript 3.9.2
This project it's a simple project of structure the Deno. In Routes you can see the HTTP methods, how: GET, POST, PUT, DELETE.
The example was worked here it's to get the chapters in description of YouTube Videos and treat the data depending your use.
The form to work with the request it's different of Node.
- Example:
The method updateChapter in youtube-chapter-controller, if it was done in Node:
updateChapter(req, res, next) {
const { id, seconds } = req.params;
// Code here...
}
The same method now done in Deno:
const updateChapter = async (
{ params, request, response }: {
params: {
id: string;
seconds: string
};
request: any;
response: any;
},
) => { //Code here...}
For to run the API developed in Deno, you need to run the script run.sh.
Example:
sudo ./run.sh
The Deno needs permissions to execute any tasks for example: access the network to provide the server, file system and others permissions. And the permissions it's flaged in command to run the Deno, so we create a script in Shell to agilize the process.