16
Node.JS Introduction Adam Hendra Brata

Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Embed Size (px)

Citation preview

Page 1: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Node.JS IntroductionAdam Hendra Brata

Page 2: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Introduction to Node.JS

Page 3: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

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

Page 4: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Javascript vs Node.JS

• Javascript

Page 5: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

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.

Page 6: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

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.

Page 7: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Synchronous VS Asynchronous I/O

Page 8: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Multi Threaded Server

Page 9: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Node.JS Server

Page 10: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

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

Page 11: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Node.JS Event Loop

Callback is an asynchronous equivalent for a function. A callback function is called at thecompletion of a given task.

Page 12: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Node.JS Processing Model

Page 13: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Node.JS Architecture

Page 14: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

Node.JS Libraries

Page 15: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

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

Page 16: Node.JS Introduction - · PDF file1/4/2017 · Node.JS Event Loop Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given

So……..