2. Content
A. Why Deno?!
B. What’s Deno?
C. Dev Point of View
D. Code Samples
Some see chaos; others see order!
Some see destruction; others see creation!
3. A. Why Deno?!
• There are many things that became mainsteam unintentionally:
• Linux, git, PHP, JavaScript, WordPress, Node!
• Regrets of Ryan Dahl:
• Promises
• Security
• Build system with GYP and without FFI
• package.json and “private” central control
• Mess of node_modules
• require() without “.js”
• index.js
• Unhandled promises
4. B. What’s Deno?
• A simple, modern and secure runtime for JavaScript & TypeScript
• Built in Rust using V8
• Secure by default
• No file, network or environment access, unless enabled
• Has built-in utilities
• Dependency inspector, code formatter, linter, testing/assertion library, etc.
• Has a set of stable standard modules that work: https://deno.land/std
• Very similar to Golang std package: https://golang.org/pkg/
• Can import modules from any location on the web
• GitHub, CDN or a personal webserver
• Provides a simple “public” hosting service for ES modules
• Ships only a single executable file!
5. C. Dev Point of View
1. Modern Javascript (ES Modules)
2. TypeScript works natively
3. Decentralized Packages
4. Top level ‘await’
5. Access to the Browser API
6. D. Code Samples (1)
import { serve } from "https://deno.land/std@0.97.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hello Worldn" });
}
// deno lint --unstable
// deno run --allow-net=0.0.0.0 ./httpServer.ts
// deno compile --unstable --allow-net=0.0.0.0 ./httpServer.ts
// ./httpServer
7. D. Code Samples (2)
interface Person {
name: string;
surname: string;
}
interface Data {
rows: Array<Person>;
update?: Date;
}
const filePath = './data.json';
const data: Data = readJson(filePath);
data.rows.push({ name: 'Jane', surname: 'Smith' });
data.update = new Date();
const result = writeJson(filePath, data);
console.log(result ? 'success' : 'error');
// deno run --allow-read --allow-write ./fileOps.ts
function readJson(filePath: string): Data {
const text = Deno.readTextFileSync(filePath);
const temp = JSON.parse(text);
if (!temp) throw new Error('failed to parse data file’);
const data: Data = temp as Data;
return data;
}
function writeJson(filePath: string, data: Data): boolean {
try {
const text = JSON.stringify(data, null, ' ‘);
Deno.writeTextFileSync(filePath, text);
return true;
} catch (ex) {
console.error(ex.message);
return false;
}
}
8. The End
Thank you
https://deno.land/
Ryan Dahl’s video:
https://www.youtube.com/watch?v=M3BM9TB-8yA
https://golang.org/pkg/
https://www.rust-lang.org/
Recommended URLs: