Deno
JaxNode July 2020
Deno pronounced
Dee-No
What is Deno
- A runtime for TypeScript and JavaScript
- Built with Rust, v8, Tokio, TypeScript and JS
- CLI tools
- Webservers
- Micro-services
- Back-end server tools
History
- Ryan Dahl introduced Node.js 2009
- He left the project 2012
- Node became extremely popular
- Dahl introduced Deno two years ago
Is Deno a replacement
for Node?
- No
Node shortcomings
- Everything is asynchronous
- Forces developers to program using callbacks
- Dahl liked Go's approach to synchronous with channels
- Modules not always compatible with browsers
- No 'window' object
- No built in fetch
Deno features
- Write in either TypeScript or JavaScript
- Not tied to NPM
- Standard Core library
- Full support for 'import' and 'export'
- Deno.land site hosts some modules
- Enhanced security through flags
Deno shortcomings
- 1.0, now 1.2
- Not full support for 3rd party services
- Not backwards compatible with NPM
- Requires flags for some features to work
- Is it safe to use in Prod?
Deno
- Chocolatey (Windows)
- Homebrew (macOS)
- Cargo
- Shell
- PowerShell
Install
- choco install deno
- brew install deno
- cargo install deno
-
curl -fsSL https://deno.land/x/install/install.sh | sh
-
iwr https://deno.land/x/install/install.ps1 -useb | iex
Sample
// hello.ts
const message: string = 'Hello JaxNode!';
console.log(message);
// run the following command > deno run hello.ts
// httpserve.ts
import { serve } from "https://deno.land/std@0.59.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
Security flags
- deno run --allow-net
- --allow-net=api.google.com
- deno run --allow-write
- deno run --allow-read
- --allow-read=/tmp
- deno run --allow-all
- deno run --allow-env
Existing frameworks
- Oak for webservices
- opine (Express clone)
- lodash
- moment
- redis
Package managers
- deno.land
- pika.dev
- jspm.io
Modules
- No 'node_modules' folder
- modules are downloaded and cached in the $HOME/Library/Cache/deno
- Can also store in your src
Deno Tooling
- Use Cargo to create specific Deno builds
- Deno bundle
- Deno Test
- Deno Linter
- Deno Install
- Deno info
- Deno fmt
Deno Test
- asserts.ts module had a bug in 1.12
- Looks for files that 'test' in the filename
- Create tests with Deno.test(name, fn())
Deno Install
- > deno install
- deno install --allow-net --allow-read -n serve https://deno.land/std/http/file_server.ts -p 8080
- > cd ~/ && serve
WebAssembly
- Deno supports WASM through V8
- Deno is compiled with Rust
- Many Deno modules have coded in Rust, and converted into WebAssembly
- SQLite Deno module is C compiled into Wasm with emscripten
Deploying Deno
- Host as a Server app
- Deploy using Docker
- Heroku has a buildpack for Deno, will require Procfile
- Vercel (formally Zeit) lets you deploy deno as micro-services
Demo Deno
Questions?
deno
By David Fekke
deno
An introduction to the Deno runtime for TypeScript and JavaScript
- 974