Slide 1

Slide 1 text

@deepu105 #devoxxUkraine By Deepu K Sasidharan, XebiaLabs November 2, 2019 Building Native TypeScript applications using Deno

Slide 2

Slide 2 text

@deepu105 #devoxxUkraine About Me Deepu K Sasidharan OSS aficionado Co-lead Senior developer Robotics & Astronomy enthusiast https://www.packtpub.com/application-development/full-stack-development-jhipster

Slide 3

Slide 3 text

@deepu105 #devoxxUkraine About XebiaLabs

Slide 4

Slide 4 text

@deepu105 #devoxxUkraine What about you? How many of you are JavaScript developers? How many are web developers? Who likes TypeScript more than JavaScript? Any NodeJS application developers?

Slide 5

Slide 5 text

@deepu105 #devoxxUkraine What about you? Have you heard of Deno?

Slide 6

Slide 6 text

@deepu105 #devoxxUkraine What is Deno? A modern JavaScript/TypeScript runtime & scripting environment Created by Ryan Dahl(Creator of NodeJS) in 2018 Built with V8, Rust and Tokio Secure by default Built in tooling Execute remote scripts Lightweight multi-platform executable(~10MB) Many inspirations from Go and Rust https://deno.land/

Slide 7

Slide 7 text

Does not use NPM No more node_modules hell!

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

@deepu105 #devoxxUkraine

Slide 10

Slide 10 text

@deepu105 #devoxxUkraine What is TypeScript A strict syntactical superset of JavaScript - upto ES2019(ES10) JavaScript that scales Optional static typing support Transpiles to JavaScript Maintained by Microsoft with major collaboration from Google Great editor and IDE support

Slide 11

Slide 11 text

@deepu105 #devoxxUkraine Why

Slide 12

Slide 12 text

@deepu105 #devoxxUkraine Why TypeScript Type safety and Type inference Great IDE support Easier refactoring Better linting and error identification Features from the Future Additional language features Much better code style

Slide 13

Slide 13 text

I hate transpiling my code, but if have to do so I’ll do it with TypeScript

Slide 14

Slide 14 text

Getting started!

Slide 15

Slide 15 text

@deepu105 #devoxxUkraine Install Deno brew install deno or cargo install deno_cli or curl -fsSL https://deno.land/x/install/install.sh | sh Or using PowerShell iwr https://deno.land/x/install/install.ps1 -useb | iex

Slide 16

Slide 16 text

Main features

Slide 17

Slide 17 text

@deepu105 #devoxxUkraine Execute remote scripts deno https://deno.land/std/examples/welcome.ts

Slide 18

Slide 18 text

@deepu105 #devoxxUkraine Secure by default Scripts can't access files, the environment, subprocesses or the network unless specifically allowed by the script during execution or with flags --allow-all --allow-env --allow-write --allow-net --allow-run ● Granular permissions ● Permissions can be revoked ● Permissions whitelist support

Slide 19

Slide 19 text

@deepu105 #devoxxUkraine Secure by default

Slide 20

Slide 20 text

@deepu105 #devoxxUkraine Standard modules ● colors - ANSI colors on console ● datetime - Datetime parse utilities ● encoding - Read CSV & TOML ● flags - CLI argument parser ● fs - Filesystem API ● http - HTTP server framework ● log - Logging framework ● media_types - Resolve media types ● prettier - Prettier formatting API ● strings - String utils ● testing - Testing utils ● uuid - UUID support ● ws - Websocket client/server

Slide 21

Slide 21 text

@deepu105 #devoxxUkraine Supports only ES Modules ● require() is not supported, so no confusion with import syntax ● No "magical" module resolution ● Third party modules are imported by URL(Local and remote) ● Remote code is fetched only once and catched globally for later use ● Remote code is considered immutable and never updated unless --reload flag is used ● Dynamic imports ● Supports import maps ● Third party modules in https://deno.land/x/ ● NPM modules can be used if required as simple local file URL or from https://jspm.io/ or https://www.pika.dev/

Slide 22

Slide 22 text

@deepu105 #devoxxUkraine Supports only ES Modules

Slide 23

Slide 23 text

@deepu105 #devoxxUkraine Built in tooling ● dependency inspector (deno info) ● Bundler (deno bundle) ● Installer (deno install) ● Test runner (deno test) ● Type info (deno types) ● code formatter, uses prettier (deno fmt) ● linter [planned] (deno lint) ● Debugger [planned] (--debug)

Slide 24

Slide 24 text

@deepu105 #devoxxUkraine Browser compatibility ● Deno programs which are written completely in JavaScript and do not use the global Deno ● Deno programs in Typescript bundled into JavaScript and do not use the global Deno

Slide 25

Slide 25 text

@deepu105 #devoxxUkraine Async actions return promise ● No call back hell ● Consistent API across the standard modules ● Works great with async/await

Slide 26

Slide 26 text

@deepu105 #devoxxUkraine Top level await ● Simplifies code ● Makes code more readable ● Works great with Deno async API

Slide 27

Slide 27 text

@deepu105 #devoxxUkraine Web assembly support https://wasdk.github.io/WasmFiddle/?pkku4

Slide 28

Slide 28 text

@deepu105 #devoxxUkraine Subprocess using web workers ● Async API ● Uses web workers ● One V8 instance per worker

Slide 29

Slide 29 text

@deepu105 #devoxxUkraine Options

Slide 30

Slide 30 text

Why is Deno better than NodeJS

Slide 31

Slide 31 text

@deepu105 #devoxxUkraine Advantages ● Easy to install - Single lightweight binary ● Secure by default, Fine grained privileges ● Simpler module resolution ● Decentralized and globally cached third party modules ● No dependency on package managers or package registries(No NPM, No Yarn, No node_modules) ● Native TypeScript support ● Follows web standards and modern language features ● Remote script runner ● Built in tooling

Slide 32

Slide 32 text

Why does it matter

Slide 33

Slide 33 text

@deepu105 #devoxxUkraine Why does it matter ● Dynamic languages are still important ○ Data science ○ Scripting ○ Tooling ○ CLI ● NodeJS ecosystem has become too heavy and bloated ● Many Python/NodeJS use cases can be replaced with TypeScript using Deno ○ TypeScript provides better developer experience ○ Consistent and documentable API ○ Easier to build and distribute ○ Does not download the internet all the time ○ More secure

Slide 34

Slide 34 text

@deepu105 #devoxxUkraine Challenges ● Fragmentation ○ Not compatible with most of the NPM modules ○ Lib authors would have to publish a Deno compatible build(Not difficult but en extra step) ● Migrating existing NodeJS apps will not be easy due to incompatible API ● Bundles are not optimized so might need tooling or improvements there ● Stability as Deno is quite new (NodeJS is battle tested) ● Not production ready

Slide 35

Slide 35 text

@deepu105 #devoxxUkraine A Deno proxy application in action $ deno install my-proxy deno_app.ts --allow-net $ my-proxy https://google.com

Slide 36

Slide 36 text

Still in active development

Slide 37

Slide 37 text

1.0 planned for end of year https://github.com/denoland/deno/issues/2473

Slide 38

Slide 38 text

10 Things I Regret About Node.js - Ryan Dahl - https://www.youtube.com/watch?v=M3BM9TB-8yA Deno, a new way to JavaScript - Ryan Dahl - https://www.youtube.com/watch?v=z6JRlx5NC9E Website - https://deno.land/

Slide 39

Slide 39 text

https://jhipster.tech @java_hipster Full Stack Development with JHipster ● Amazon: https://goo.gl/k1NBAv ● Packt: https://goo.gl/XvQLeN

Slide 40

Slide 40 text

Thank you! Please rate the talk if you liked it!