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

How NodeJS Works

How NodeJS Works

A short overview of how NodeJS actually works for CNTU students.

8fac73c8695395b3ec634a0be7cb5fc6?s=128

Volodymyr Rudyi

January 30, 2020
Tweet

Transcript

  1. How NodeJS Works? Volodymyr Rudyi

  2. Intro CEO @ AgileVision Software Engineer Studied at CNTU some

    time ago ;)
  3. A bit of JavaScript history • Created in 1993 •

    First standard in 1996 • Latest standard in 2017 • Used on clients and servers
  4. What’s NodeJS then?

  5. Execution environments 101 • Allows executing JavaScript code • Works

    on a particular platform/set of platforms • Provides an additional API to interact with the platform
  6. None
  7. Other well-known execution environments •Web browsers

  8. NodeJS Provides tools for • Interaction with file systems (fs)

    • Console (console.log) • Timer (setTimeout) • Debugging and profiling (Inspector/Chrome Dev Tools) • Thousands of other stuff • These features are called NodeJS API
  9. APIs are written in

  10. How it works? console.log() C++ code NodeJS

  11. Fun fact NodeJS doesn’t know how to execute JavaScript

  12. … but V8 knows It’s like little Yoda inside a

    spaceship…
  13. V8 • Not a Mustang GT • A JavaScript Engine

    developed by Google • Written in C++ • Knows how to parse and execute JavaScript code • Knows nothing about browsers, files, operating systems
  14. How it really works then? JavaScript Code API (Written in

    C+++) NodeJS V8
  15. Summary • Programmer writes JavaScript code and passes it to

    the NodeJS(Execution Environment) • Execution environment passes the code to the V8 engine • V8 engine parses code and executes it • Each time API is used, V8 calls the corresponding code from the execution environment (using so-called “bindings”)
  16. Idea • It’s possible to create your own custom execution

    environment • It’s should be easy
  17. Options Embed V8 Embed Mozilla Rhino

  18. Embedding V8 - Pros • Wide set of features •

    Performance • Inspection/analysis using Chrome Dev Tools protocol • It’s native
  19. Embedding V8 - Cons • You need to know C++

    • It’s native
  20. Embedding Rhino - Pros • Java-based API • Can be

    almost instantly embedded to some platforms, like Android • Non-native code running in JVM
  21. Embedding Rhino - Cons • Java-based API • Won’t work

    on platforms like iOS
  22. Questions?