项目作者: chesterheng

项目描述 :
Deno: The Complete Guide Zero to Mastery
高级语言: JavaScript
项目地址: git://github.com/chesterheng/deno-complete-guide.git
创建时间: 2020-08-16T14:30:11Z
项目社区:https://github.com/chesterheng/deno-complete-guide

开源协议:

下载


Deno: The Complete Guide Zero to Mastery

Table of Contents

Section 2: 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

  1. 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”
  1. open /Users/chesterheng/.deno/bin/deno
  2. /Users/chesterheng/.deno/bin/deno --help
  3. deno

⬆ back to top

7. Quick Note: Installing Deno

Deno online editor

⬆ back to top

10. Setting Up Our Developer Environment

  1. deno run deno.js
  2. deno run deno2.ts

deno.js

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())


deno2.ts

typescript 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:
      1. {
      2. "deno.enable": true
      3. }

⬆ back to top

12. Our First Deno App

  1. deno run deno.js 'love'

deno.js

javascript 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

  1. deno run deno.js 'love' 'ryan'

deno.js

javascript 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

  1. deno run deno.js

deno.js

javascript 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

22. Deno Game Changers 2

Deno

  • First class TypeScript
  • std@0.65.0/examples">ES Modules
    1. import "https://deno.land/std@0.65.0/examples/welcome.ts"
    2. import "https://deno.land/std@0.65.0/examples/chat/server.ts"
  • Security first
    1. deno run --allow-net deno2.js
  • “Decentralized” modules: developer can host modules anywhere ->
  • std@0.65.0">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

  1. pub allow_read: PermissionState,
  2. pub read_allowlist: HashSet<PathBuf>,
  3. pub allow_write: PermissionState,
  4. pub write_allowlist: HashSet<PathBuf>,
  5. pub allow_net: PermissionState,
  6. pub net_allowlist: HashSet<String>,
  7. pub allow_env: PermissionState,
  8. pub allow_run: PermissionState,
  9. pub allow_plugin: PermissionState,
  10. pub allow_hrtime: PermissionState,

⬆ back to top

26. Deno Permissions

27. Deno Permissions 2

28. Deno Permissions 3

  • 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
  1. deno run --allow-net deno2.js
  2. deno run --allow-env main.ts
  3. deno run --allow-all main.ts
  4. deno run -A main.ts
  5. deno run -help
  6. deno install --allow-env main.ts
  7. section-03
  8. deno run -A Drakefile.ts hello

deno2.js

javascript 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

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()


main.ts

typescript 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

console local: deno3.js type: JavaScript deps: deno3.js └── deno2.js


deno2.js

javascript export function denode(input) { if (input.toLowerCase() === 'node') { return input.split("").sort().join("") } return input; }


deno3.js

javascript import { denode } from './deno2.js' console.log(denode("NODE"));

⬆ back to top

30. URL Modules


deno info deno3.js

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


deno info 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


deno2.js

javascript export function denode(input) { if (input.toLowerCase() === 'node') { return input.split("").sort().join("") } return input; }


deno3.js

javascript 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

  • std@0.66.0">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

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

⬆ back to top

32. 3rd Party Modules

⬆ back to top

33. Deno Caching

Linking to third party code

  1. open $HOME/Library/Caches/deno

deno run deno3.js

console Download https://deno.land/std@0.66.0/examples/welcome.ts Check deno3.js Welcome to Deno 🦕 DENO


deno run deno3.js

console Check deno3.js Welcome to Deno 🦕 DENO


deno run —reload deno3.js

console Download https://deno.land/std@0.66.0/examples/welcome.ts Check deno3.js Welcome to Deno 🦕 DENO

⬆ back to top

34. Deno Caching 2

⬆ 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

43. Deno Tooling 2

⬆ back to top

Section 5: TypeScript

⬆ back to top

Section 6: Deno File I/O - Planets Project

⬆ back to top

Section 7: Exercise: SpaceX Launch Data

⬆ back to top

Section 8: NASA Project: Deno For Backend Development

⬆ back to top

Section 9: NASA Project: Deno Production And The Cloud (Docker + AWS)

⬆ back to top

Section 10: Where To Go From Here?

⬆ back to top

Section 11: Bonus: How JavaScript Works

⬆ back to top

Section 12: Bonus: Learning TypeScript

⬆ back to top

Section 13: Bonus: HTTP, AJAX, JSON and APIs

⬆ back to top