Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Native TypeScript applications using Deno - Devoxx Ukraine 2019

Building Native TypeScript applications using Deno - Devoxx Ukraine 2019

You probably already know that TypeScript is great. But do you know about Deno? Deno is what NodeJS should have been. Deno is a secure JavaScript/TypeScript runtime built with V8 & Rust. It was created by the original creator of NodeJS. It is aimed to be the better alternative for NodeJS. Ryan Dahl aims to fix issues in NodeJS with Deno. In this talk, we will see what Deno is and why it is better than NodeJS for TypeScript native applications.

Deepu K Sasidharan

November 02, 2019
Tweet

More Decks by Deepu K Sasidharan

Other Decks in Programming

Transcript

  1. @deepu105 #devoxxUkraine By Deepu K Sasidharan, XebiaLabs November 2, 2019

    Building Native TypeScript applications using Deno
  2. @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
  3. @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?
  4. @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/
  5. @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
  6. @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
  7. I hate transpiling my code, but if have to do

    so I’ll do it with TypeScript
  8. @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
  9. @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
  10. @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
  11. @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/
  12. @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)
  13. @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
  14. @deepu105 #devoxxUkraine Async actions return promise • No call back

    hell • Consistent API across the standard modules • Works great with async/await
  15. @deepu105 #devoxxUkraine Top level await • Simplifies code • Makes

    code more readable • Works great with Deno async API
  16. @deepu105 #devoxxUkraine Subprocess using web workers • Async API •

    Uses web workers • One V8 instance per worker
  17. @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
  18. @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
  19. @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
  20. @deepu105 #devoxxUkraine A Deno proxy application in action $ deno

    install my-proxy deno_app.ts --allow-net $ my-proxy https://google.com
  21. 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/