May 30, 2020 • ☕️ 2 min read
日本語

Deno 1.0 is released in 2020.05.13. As the creator is Ryan Dahl, who made the node.js, it’s worth trying.

Example

https://github.com/thundermiracle/try-deno

After using Deno, the cons in my opinion

1. TypeScript is built in supported

Checking in compilation is very important in team work, especially when team members are newbies. TypeScript could force all members to same standards and reduce stupid bugs.

2. Deno is in the sandbox which is more secure

exp: starting a server

Copy
deno run --allow-net ./src/server.ts

no flag --allow-net, Deno will refuse starting the API server.

3. import instead of require

CJS is good, but I like import.

nodejs
Copy
// Bad(☔☔☔)
const fs = require("fs");
Deno
Copy
// Good(🌟🌟🌟)
import { readFileStrSync } from "https://deno.land/std/fs/mod.ts";

4. await, async is first class member

From nodejs v14.3, await, async became first class member, too. But about old nodejs, even LTS v12:

nodejs
Copy
// Bad(☔☔☔)
async function job1() {...}
async function job2() {...}

// wrapper for async functions
async function doAllJobs() {
  await job1();
  await job2();
}
doAllJobs();
Deno
Copy
// Good(🌟🌟🌟)
async function job1() {...}
async function job2() {...}

await job1();
await job2();

5. Goodbye! node_modules

We need install node_modules in every nodejs project which is a little annoying.

Deno is using url import, packages are downloaded & cached in AppData folder in Windows like other languages: .Net Core or PHP, and shared between all projects which really saves space and installing time.

nodejs
Copy
# after git clone
# Bad(☔☔☔)
cd project1-folder
npm install  # tremendous duplicated node_modules
npm start

cd project2-folder
npm install  # tremendous duplicated node_modules
npm start
Deno
Copy
# after git clone
// Good(🌟🌟🌟)
cd project1-folder
deno run server.ts # Deno will download & cache packages automatically if not exist

cd project2-folder
deno run server.ts # Deno will download & cache packages automatically if not exist

Finish

The other parts are very similar to express, but I like TypeScript and expect the progress of Deno in future.


ThunderMiracle

Blog part of ThunderMiracle.com