What you need to start with Deno

4 min read
Table of contents

Section 1: Deno Foundations

4. Why Deno?

  • Deno
  • Rust by Mozilla
  • TypeScript by Microsoft
  • V8 Engine by Google

⬆ back to top

5. Deno Runtime And V8 Engine

  • JS / TS -> V8 Engine -> Mobile / Web

⬆ back to top

6. Deno Installation

curl -fsSL https://deno.land/x/install/install.sh | sh
  • Deno was installed successfully to /Users/chesterheng/.deno/bin/deno
  • Manually add the directory to your $HOME/.bash_profile (or similar)
    • export DENO_INSTALL=“/Users/chesterheng/.deno”
    • export PATH=“$DENO_INSTALL/bin:$PATH”
open /Users/chesterheng/.deno/bin/deno
/Users/chesterheng/.deno/bin/deno --help
deno

⬆ back to top

7. Quick Note: Installing Deno

Deno online editor

⬆ back to top

10. Setting Up Our Developer Environment

deno run deno.js
deno run deno2.ts
deno.js
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())
deno2.ts
const b: string = 'Chester'
console.log(b)

⬆ back to top

11. Quick Note: Official VS Code Plugin

  • Download and enable Visual Studio Code Deno extension

  • Enable Deno for your project:

    • Create a file .vscode/settings.json in your project folder:
    {
      "deno.enable": true
    }
    

⬆ back to top

12. Our First Deno App

deno run deno.js 'love'
deno.js
const food = Deno.args[0]

if(food === 'love') {
  console.log('🦕...Deno is born!')
} else {
  console.log('🥚...this egg needs some love')
}

⬆ back to top

13. Exercise: Our First Deno App

deno run deno.js 'love' 'ryan'
deno.js
const food = Deno.args[0];
const parent = Deno.args[1];
if (food === 'love' && parent === 'ryan') {
   console.log('🦕...Deno is born!')
}

⬆ back to top

15. Deno Internals And Architecture

Node JSDeno
EngineV8V8
Written InC++Rust
Asynchronous I/OLIBUVTOKIO

⬆ back to top

17. Deno Metrics

deno run deno.js
deno.js
setTimeout(() => {
  console.log('check')
  console.table(Deno.metrics())
}, 1000)

⬆ back to top

18. Exercise: Deno Architecture

When do we run the Rust code?

  • Deno.
  • window.
Node JSDeno
Window Objectglobalwindow
window.fetchnode-fetchavailable

⬆ back to top

Section 3: Deno vs Node

21. Deno Game Changers

Deno

import "https://deno.land/[email protected]/examples/welcome.ts"
import "https://deno.land/[email protected]/examples/chat/server.ts"
  • Security first
deno run --allow-net deno2.js

⬆ back to top

24. Single Executable To Rule Them All

”deno compile” into executable

⬆ back to top

25. Deno Security

Permissions for CLI

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,

⬆ back to top

26. Deno Permissions

  • Whitelisting is the practice of explicitly allowing some identified entities access to a particular privilege, service, mobility, access or recognition. It is the opposite of blacklisting.
  • Drake — a task runner for Deno
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
deno2.js
import "https://deno.land/[email protected]/examples/welcome.ts"
import "https://deno.land/[email protected]/examples/chat/server.ts"
Drakefile.ts
import { desc, run, task, sh } from "https://deno.land/x/[email protected]/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()
main.ts
console.log("Hello", Deno.env.get("USER"));

⬆ back to top

Section 4: Deno Modules And Tooling

29. How Modules Work In Deno

deno info deno3.js
local: deno3.js
type: JavaScript
deps:
deno3.js
  └── deno2.js
deno2.js
export function denode(input) {
  if (input.toLowerCase() === 'node') {
    return input.split("").sort().join("")
  }
  return input;
}
deno3.js
import { denode } from './deno2.js'

console.log(denode("NODE"));

⬆ back to top

30. URL Modules

deno info deno3.js
Download https://deno.land/[email protected]/examples/welcome.ts
local: deno3.js
type: JavaScript
deps:
deno3.js
  ├── deno2.js
  └── https://deno.land/[email protected]/examples/welcome.ts
deno info https://deno.land/[email protected]/examples/welcome.ts
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/[email protected]/examples/welcome.ts
deno2.js
export function denode(input) {
  if (input.toLowerCase() === 'node') {
    return input.split("").sort().join("")
  }
  return input;
}
deno3.js
import { denode } from './deno2.js'
import "https://deno.land/[email protected]/examples/welcome.ts"

console.log(denode("NODE"));

⬆ back to top

31. Standard Library

deno info https://deno.land/std/http/server.ts
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/[email protected]/http/server.ts
Download https://deno.land/[email protected]/encoding/utf8.ts
Download https://deno.land/[email protected]/io/bufio.ts
Download https://deno.land/[email protected]/_util/assert.ts
Download https://deno.land/[email protected]/async/mod.ts
Download https://deno.land/[email protected]/http/_io.ts
Download https://deno.land/[email protected]/async/deferred.ts
Download https://deno.land/[email protected]/async/delay.ts
Download https://deno.land/[email protected]/async/mux_async_iterator.ts
Download https://deno.land/[email protected]/async/pool.ts
Download https://deno.land/[email protected]/textproto/mod.ts
Download https://deno.land/[email protected]/http/http_status.ts
Download https://deno.land/[email protected]/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/[email protected]/encoding/utf8.ts
  ├─┬ https://deno.land/[email protected]/io/bufio.ts
  │ ├── https://deno.land/[email protected]/bytes/mod.ts
  │ └── https://deno.land/[email protected]/_util/assert.ts
  ├── https://deno.land/[email protected]/_util/assert.ts
  ├─┬ https://deno.land/[email protected]/async/mod.ts
  │ ├── https://deno.land/[email protected]/async/deferred.ts
  │ ├── https://deno.land/[email protected]/async/delay.ts
  │ ├─┬ https://deno.land/[email protected]/async/mux_async_iterator.ts
  │ │ └── https://deno.land/[email protected]/async/deferred.ts
  │ └── https://deno.land/[email protected]/async/pool.ts
  └─┬ https://deno.land/[email protected]/http/_io.ts
    ├── https://deno.land/[email protected]/io/bufio.ts
    ├─┬ https://deno.land/[email protected]/textproto/mod.ts
    │ ├── https://deno.land/[email protected]/bytes/mod.ts
    │ └── https://deno.land/[email protected]/encoding/utf8.ts
    ├── https://deno.land/[email protected]/_util/assert.ts
    ├── https://deno.land/[email protected]/encoding/utf8.ts
    ├─┬ https://deno.land/[email protected]/http/server.ts
    │ ├── https://deno.land/[email protected]/encoding/utf8.ts
    │ ├── https://deno.land/[email protected]/io/bufio.ts
    │ ├── https://deno.land/[email protected]/_util/assert.ts
    │ ├── https://deno.land/[email protected]/async/mod.ts
    │ └── https://deno.land/[email protected]/http/_io.ts
    └── https://deno.land/[email protected]/http/http_status.ts

⬆ back to top

32. 3rd Party Modules

⬆ back to top

33. Deno Caching

Linking to third party code

open $HOME/Library/Caches/deno
deno run deno3.js
Download https://deno.land/[email protected]/examples/welcome.ts
Check deno3.js
Welcome to Deno 🦕
DENO
deno run deno3.js
Check deno3.js
Welcome to Deno 🦕
DENO
deno run —reload deno3.js
Download https://deno.land/[email protected]/examples/welcome.ts
Check deno3.js
Welcome to Deno 🦕
DENO

⬆ back to top

35. NPM for Deno

⬆ back to top

36. Managing Module Versions

⬆ back to top

37. Where the Bleep is package.json?

⬆ back to top

38. Deps.ts

⬆ back to top

39. Locking Dependencies

⬆ back to top

40. Deno Upgrade

⬆ back to top

41. Reviewing Deno Modules

⬆ back to top

42. Deno Tooling

⬆ back to top

Section 5: TypeScript

⬆ back to top

Section 6: Deno File I/O

⬆ back to top