Deno: The Complete Guide Zero to Mastery
curl -fsSL https://deno.land/x/install/install.sh | sh
open /Users/chesterheng/.deno/bin/deno
/Users/chesterheng/.deno/bin/deno --help
deno
deno run deno.js
deno run deno2.ts
javascript
const food = Deno.args[0];
const parent = Deno.args[1];
if (food === 'love' && parent === 'ryan') {
console.log('🦕...Deno is born!')
} else {
console.log('🥚...this egg needs some love')
}
setTimeout(() => {
console.log('check')
}, 1000)
console.table(Deno.metrics())
typescript
const b: string = 'Chester'
console.log(b)
{
"deno.enable": true
}
deno run deno.js 'love'
javascript
const food = Deno.args[0]
if(food === 'love') {
console.log('🦕...Deno is born!')
} else {
console.log('🥚...this egg needs some love')
}
deno run deno.js 'love' 'ryan'
javascript
const food = Deno.args[0];
const parent = Deno.args[1];
if (food === 'love' && parent === 'ryan') {
console.log('🦕...Deno is born!')
}
Node JS | Deno | |
---|---|---|
Engine | V8 | V8 |
Written In | C++ | Rust |
Asynchronous I/O | LIBUV | TOKIO |
deno run deno.js
javascript
setTimeout(() => {
console.log('check')
console.table(Deno.metrics())
}, 1000)
When do we run the Rust code?
Node JS | Deno | |
---|---|---|
Window Object | global | window |
window.fetch | node-fetch | available |
Deno
import "https://deno.land/std@0.65.0/examples/welcome.ts"
import "https://deno.land/std@0.65.0/examples/chat/server.ts"
deno run --allow-net deno2.js
“deno compile” into executable
pub allow_read: PermissionState,
pub read_allowlist: HashSet<PathBuf>,
pub allow_write: PermissionState,
pub write_allowlist: HashSet<PathBuf>,
pub allow_net: PermissionState,
pub net_allowlist: HashSet<String>,
pub allow_env: PermissionState,
pub allow_run: PermissionState,
pub allow_plugin: PermissionState,
pub allow_hrtime: PermissionState,
deno run --allow-net deno2.js
deno run --allow-env main.ts
deno run --allow-all main.ts
deno run -A main.ts
deno run -help
deno install --allow-env main.ts
section-03
deno run -A Drakefile.ts hello
javascript
import "https://deno.land/std@0.65.0/examples/welcome.ts"
import "https://deno.land/std@0.65.0/examples/chat/server.ts"
typescript
import { desc, run, task, sh } from "https://deno.land/x/drake@v1.2.6/mod.ts";
desc("Minimal Drake task");
task("hello", [], async function() {
console.log("Hello from Drake!");
await sh("deno run --allow-env main.ts");
await sh("echo Hello World");
});
run()
typescript
console.log("Hello", Deno.env.get("USER"));
console
local: deno3.js
type: JavaScript
deps:
deno3.js
└── deno2.js
javascript
export function denode(input) {
if (input.toLowerCase() === 'node') {
return input.split("").sort().join("")
}
return input;
}
javascript
import { denode } from './deno2.js'
console.log(denode("NODE"));
console
Download https://deno.land/std@0.66.0/examples/welcome.ts
local: deno3.js
type: JavaScript
deps:
deno3.js
├── deno2.js
└── https://deno.land/std@0.66.0/examples/welcome.ts
console
local: /Users/chesterheng/Library/Caches/deno/deps/https/deno.land/aaa5f7b759111e731af7b564810dc454f6ecbeb452c020834e6e6782a3fd973e
type: TypeScript
compiled: /Users/chesterheng/Library/Caches/deno/gen/https/deno.land/aaa5f7b759111e731af7b564810dc454f6ecbeb452c020834e6e6782a3fd973e.js
deps:
https://deno.land/std@0.66.0/examples/welcome.ts
javascript
export function denode(input) {
if (input.toLowerCase() === 'node') {
return input.split("").sort().join("")
}
return input;
}
javascript
import { denode } from './deno2.js'
import "https://deno.land/std@0.66.0/examples/welcome.ts"
console.log(denode("NODE"));
console
Download https://deno.land/std/http/server.ts
Warning Implicitly using latest version (0.66.0) for https://deno.land/std/http/server.ts
Download https://deno.land/std@0.66.0/http/server.ts
Download https://deno.land/std@0.66.0/encoding/utf8.ts
Download https://deno.land/std@0.66.0/io/bufio.ts
Download https://deno.land/std@0.66.0/_util/assert.ts
Download https://deno.land/std@0.66.0/async/mod.ts
Download https://deno.land/std@0.66.0/http/_io.ts
Download https://deno.land/std@0.66.0/async/deferred.ts
Download https://deno.land/std@0.66.0/async/delay.ts
Download https://deno.land/std@0.66.0/async/mux_async_iterator.ts
Download https://deno.land/std@0.66.0/async/pool.ts
Download https://deno.land/std@0.66.0/textproto/mod.ts
Download https://deno.land/std@0.66.0/http/http_status.ts
Download https://deno.land/std@0.66.0/bytes/mod.ts
local: /Users/chesterheng/Library/Caches/deno/deps/https/deno.land/41079ae77abd890bc4e9a389c6b449dda2f6c8e75955df8af2ff39094c277f04
type: TypeScript
compiled: /Users/chesterheng/Library/Caches/deno/gen/https/deno.land/41079ae77abd890bc4e9a389c6b449dda2f6c8e75955df8af2ff39094c277f04.js
deps:
https://deno.land/std/http/server.ts
├── https://deno.land/std@0.66.0/encoding/utf8.ts
├─┬ https://deno.land/std@0.66.0/io/bufio.ts
│ ├── https://deno.land/std@0.66.0/bytes/mod.ts
│ └── https://deno.land/std@0.66.0/_util/assert.ts
├── https://deno.land/std@0.66.0/_util/assert.ts
├─┬ https://deno.land/std@0.66.0/async/mod.ts
│ ├── https://deno.land/std@0.66.0/async/deferred.ts
│ ├── https://deno.land/std@0.66.0/async/delay.ts
│ ├─┬ https://deno.land/std@0.66.0/async/mux_async_iterator.ts
│ │ └── https://deno.land/std@0.66.0/async/deferred.ts
│ └── https://deno.land/std@0.66.0/async/pool.ts
└─┬ https://deno.land/std@0.66.0/http/_io.ts
├── https://deno.land/std@0.66.0/io/bufio.ts
├─┬ https://deno.land/std@0.66.0/textproto/mod.ts
│ ├── https://deno.land/std@0.66.0/bytes/mod.ts
│ └── https://deno.land/std@0.66.0/encoding/utf8.ts
├── https://deno.land/std@0.66.0/_util/assert.ts
├── https://deno.land/std@0.66.0/encoding/utf8.ts
├─┬ https://deno.land/std@0.66.0/http/server.ts
│ ├── https://deno.land/std@0.66.0/encoding/utf8.ts
│ ├── https://deno.land/std@0.66.0/io/bufio.ts
│ ├── https://deno.land/std@0.66.0/_util/assert.ts
│ ├── https://deno.land/std@0.66.0/async/mod.ts
│ └── https://deno.land/std@0.66.0/http/_io.ts
└── https://deno.land/std@0.66.0/http/http_status.ts
open $HOME/Library/Caches/deno
console
Download https://deno.land/std@0.66.0/examples/welcome.ts
Check deno3.js
Welcome to Deno 🦕
DENO
console
Check deno3.js
Welcome to Deno 🦕
DENO
console
Download https://deno.land/std@0.66.0/examples/welcome.ts
Check deno3.js
Welcome to Deno 🦕
DENO