node.js introduction - · pdf file1/4/2017 · node.js event loop callback is an...
TRANSCRIPT
Node.JS IntroductionAdam Hendra Brata
Introduction to Node.JS
Javascript vs Node.JS
• Javascript• JavaScript is a language that runs inside web browsers as
part of documents loaded by the browser.
• Javascript gives behaviour to your pages (HTML gives semantic structure, CSS gives form or look and feel).
• Normally, alongside HTML and CSS, JavaScript is one of the three core technologies of World Wide Web content production
Javascript vs Node.JS
• Javascript
Javascript vs Node.JS
• Node.JS• Node.js® is a JavaScript runtime built on Chrome's V8
JavaScript engine.
• Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
• Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
Javascript vs Node.JS
• Node.JS • Node's goal is to provide an easy way to build scalable
network programs.
• JavaScript usually used in client-side but node.js puts the JavaScript on server-side thus making communication between client and server will happen in same language
• Servers are normally thread based but Node.JS is “Event” based. Node.JS serves each request in a Evented loop that can able to handle simultaneous requests.
• Node.JS programs are executed by V8 Javascript enginethe same used by Google chrome browser.
Synchronous VS Asynchronous I/O
Multi Threaded Server
Node.JS Server
Threads VS Asynchronous Event-driven
Threads Asynchronous Event-driven
Lock application / request with listener-workers threads
only one thread, which repeatedly fetches an event
Using incoming-request model Using queue and then processes it
multithreaded server might block the request which might involve multiple events
manually saves state and then goes on to process the next event
Using context switching no contention and no context switches
Using multithreading environments where listener and workers threads are used frequently to take an incoming-request lock
Using asynchronous I/O facilities (callbacks, not poll/select or O_NONBLOCK) environments
Node.JS Event Loop
Callback is an asynchronous equivalent for a function. A callback function is called at thecompletion of a given task.
Node.JS Processing Model
Node.JS Architecture
Node.JS Libraries
Node.JS
• When to use Node.JS ?• Chat/Messaging
• Real-time Applications
• Intelligent Proxies
• High Concurrency Applications
• Communication Hubs
• Internet of Things Environment
• Embedded System
So……..