What you need to start with Deno

Updated by Alok Prateek 11 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 JS Deno
Engine V8 V8
Written In C++ Rust
Asynchronous I/O LIBUV TOKIO

⬆ 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 JS Deno
Window Object global window
window.fetch node-fetch available

⬆ back to top

Section 3: Deno vs Node

21. Deno Game Changers

Deno

  • First class TypeScript
  • ES Modules

    import "https://deno.land/std@0.65.0/examples/welcome.ts"
    import "https://deno.land/std@0.65.0/examples/chat/server.ts"
  • Security first

    deno run --allow-net deno2.js
  • “Decentralized” modules: developer can host modules anywhere ->
  • Standard Library
  • Built In Tooling
  • Browser Compatible API

    • JS can run in browser with no changes
    • same window object with browser
    • fetch is available
  • Single Executable: deno
  • Async returns Promises
  • Opinionated Modules: Deno Style Guide

⬆ 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/std@0.65.0/examples/welcome.ts"
import "https://deno.land/std@0.65.0/examples/chat/server.ts"
Drakefile.ts
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()
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/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
deno info https://deno.land/std@0.66.0/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/std@0.66.0/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/std@0.66.0/examples/welcome.ts"

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

⬆ back to top

31. Standard Library

  • Deno Standard Library
  • Inspired by Go
  • Maintained by Deno team
  • Dependencies are with the 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/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

⬆ 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/std@0.66.0/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/std@0.66.0/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