- Deno: The Complete Guide Zero to Mastery
- Table of Contents
- Section 2: Deno Foundations
- 4. Why Deno?
- 5. Deno Runtime And V8 Engine
- 6. Deno Installation
- 7. Quick Note: Installing Deno
- 10. Setting Up Our Developer Environment
- 11. Quick Note: Official VS Code Plugin
- 12. Our First Deno App
- 13. Exercise: Our First Deno App
- 15. Deno Internals And Architecture
- 17. Deno Metrics
- 18. Exercise: Deno Architecture
- Section 3: Deno vs Node
- Section 4: Deno Modules And Tooling
- 29. How Modules Work In Deno
- 30. URL Modules
- 31. Standard Library
- 32. 3rd Party Modules
- 33. Deno Caching
- 34. Deno Caching 2
- 35. NPM for Deno
- 36. Managing Module Versions
- 37. Where the Bleep is package.json?
- 38. Deps.ts
- 39. Locking Dependencies
- 40. Deno Upgrade
- 41. Reviewing Deno Modules
- 42. Deno Tooling
- 43. Deno Tooling 2
- Section 5: TypeScript
- Section 6: Deno File I/O - Planets Project
- Section 7: Exercise: SpaceX Launch Data
- Section 8: NASA Project: Deno For Backend Development
- Section 9: NASA Project: Deno Production And The Cloud (Docker + AWS)
- Section 10: Where To Go From Here?
- Section 11: Bonus: How JavaScript Works
- Section 12: Bonus: Learning TypeScript
- Section 13: Bonus: HTTP, AJAX, JSON and APIs
- Deno
- Rust by Mozilla
- TypeScript by Microsoft
- V8 Engine by Google
- JS / TS -> V8 Engine -> Mobile / Web
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
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)
- 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 }
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')
}
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!')
}
Node JS | Deno | |
---|---|---|
Engine | V8 | V8 |
Written In | C++ | Rust |
Asynchronous I/O | LIBUV | TOKIO |
deno run deno.js
deno.js
setTimeout(() => {
console.log('check')
console.table(Deno.metrics())
}, 1000)
When do we run the Rust code?
- Deno.
- window.
Node JS | Deno | |
---|---|---|
Window Object | global | window |
window.fetch | node-fetch | available |
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
"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,
- 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"));
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"));
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"));
- 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
- Deno Third Party Modules
- Deno do not support CommonJS
- Deno need to know the file extension
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