KEMBAR78
Introduction to Node.js
An introduction ...
Agenda
Agenda
● What is Node.js
Agenda
● What is Node.js
● How Node.js works
Agenda
● What is Node.js
● How Node.js works
● Some Node.js examples
Agenda
● What is Node.js
● How Node.js works
● Some Node.js examples
● How to learn Node.js
Agenda
● What is Node.js
● How Node.js works
● Some Node.js examples
● How to learn Node.js
● What Node.js is good at
What is Node.js
What is Node.js
Server-side JavaScript
What is Node.js
Server-side JavaScript
Node.js is a platform built on Chrome's
JavaScript runtime.
What is Node.js
Server-side JavaScript
Node.js is a platform built on Chrome's
JavaScript runtime.
Node.js uses an event-driven, non-blocking
model to execute I/O intensive applications.
Node.js and I/O
Source : https://www.altamiracorp.com/blog/employee-posts/nodejs-basics-explained
3
Node.js and I/O
Source : https://www.altamiracorp.com/blog/employee-posts/nodejs-basics-explained
3
5
Node.js and I/O
Source : https://www.altamiracorp.com/blog/employee-posts/nodejs-basics-explained
3
5
250
Node.js and I/O
Source : https://www.altamiracorp.com/blog/employee-posts/nodejs-basics-explained
3
5
250
41,000,000
Node.js and I/O
Source : https://www.altamiracorp.com/blog/employee-posts/nodejs-basics-explained
3
5
250
41,000,000
240,000,000
Node.js Event Loop
Open File
Connect to Socket
Write to DB
Event Queue
Node.js Event Loop
Open File
Connect to Socket
Write to DB
Event Queue
Event Loop
Node.js Event Loop
Open File
Connect to Socket
Write to DB
Event Queue
File System
Network
Process
Other
Event Loop
Node.js Event Loop
Open File
Connect to Socket
Write to DB
Event Queue
File System
Network
Process
Other
Event Loop
Callbacks (e.g. File Opened)
Node.js Example
1 var fs = require('fs');
2
3 fs.readFile(filename, function(err, data) {
4 var lines = data.toString().split('n');
5 console.log(lines.length);
6 });
Node.js Stack
Node Standard Library
Node.js Stack
Node Standard Library
Node C++ Bindings
(http, socket, filesystem)
Node.js Stack
Node Standard Library
V8
threadpool
(libeio)
event loop
(libev)
crypto
(Open SSL)
dns
(c-ares)
Node C++ Bindings
(http, socket, filesystem)
Node.js Stack
Node Standard Library
Node C++ Bindings
(http, socket, filesystem)
V8
threadpool
(libeio)
event loop
(libev)
crypto
(Open SSL)
dns
(c-ares)
Getting Started
● http://nodejs.org/
● Download tar.gz
● Extract to any directory
● $ ./configure
● $ make install
Demo
● The Node.js repl
● npm and a simple webserver
Great learning resources
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
nodeschool.io
Great learning resources
codewars.com
Great learning resources
Great learning resources
Great learning resources
nodejsdublin.com
Great learning resources
nodeup.com
What is Node.js good at?
Node.js is good at ...
Node.js
Webserver DB
Client #1
Client #2
Client #3
Chat Server
Node.js is good at ...
Node.js
Webserver DB
Client #1
Client #2
Client #3
Chat Server
Node.js is good at ...
Node.js
Webserver DB
Client #1
Client #2
Client #3
Chat Server
Node.js is good at ...
Node.js
Server
File System
Producer #1
Producer #2
Producer #3
Message Queuing System
Consumer #1
Consumer #2
Consumer #3
Node.js is good at ...
Node.js
Server
File System
Producer #1
Producer #2
Producer #3
Message Queuing System
Consumer #1
Consumer #2
Consumer #3
Node.js is good at ...
Node.js
Server
File System
Producer #1
Producer #2
Producer #3
Message Queuing System
Consumer #1
Consumer #2
Consumer #3
Node.js is good at ...
Microservices
Microservices
● Small unit of functionality
Microservices
● Small unit of functionality
● About 100 lines long (can fit in your head)
Microservices
● Small unit of functionality
● About 100 lines long (can fit in your head)
● Independently deployed
Microservices
● Small unit of functionality
● About 100 lines long (can fit in your head)
● Independently deployed
● Loosely Coupled
Microservices
● Small unit of functionality
● About 100 lines long (can fit in your head)
● Independently deployed
● Loosely Coupled
● Codeable in a week
Microservices
● Small unit of functionality
● About 100 lines long (can fit in your head)
● Independently deployed
● Loosely Coupled
● Codeable in a week
● Owned by one developer
Microservice Examples
● Store json object in MongoDB
Microservice Examples
● Store json object in MongoDB
● Calculate if it is time to scale app
Microservice Examples
● Store json object in MongoDB
● Calculate if it is time to scale app
● Receive user input and forward request to
another part of your app
Node.js is good at ...
Microservices
Web Browser
HDFS HBase MySQL
AuthorisationAuthentication
Web Layer
Component
Query HBaseExpire Old Data Roll up Data
Node.js is good at ...
Microservices
Web Browser
Authentication Authorisation
Web Layer
Component
Query HBaseExpire Old Data Roll up Data
Node.js Proxy
Node.js is good at ...
Microservices
Web Browser
Authentication
Authorisation
Web Layer
Component
Query HBaseExpire Old Data Roll up Data
Node.js Proxy
Worth watching
You Only Need 100 Lines of JavaScript Pragmatic Javascript
Notable Quotables
“We, among many others, find Node.js to be
an order of magnitude faster than other
tools for developing services.”
http://www.feedhenry.com/transforming-enterprise-node-js-feedhenry/
Notable Quotables
“In real web production, in real large scale
systems, in real internet companies, node is
outperforming the java stack in every case.”
http://www.nearform.com/nodecrunch/release-the-kracken-how-paypal-
is-being-revolutionized-by-node-js-and-lean-ux
More tech talks, please!
● Java 8 language features and the runtime
● Javascript technologies and language features
● Coder dojo
● Docker and LXC
● Build tools like Gradle and Grunt
● Working in real-life with Scala and Java
● Linux command line, environment tips and VI.
● The Linux OS in general (Kernal and system directories)
● Architecture
“We want Volunteers,
not Conscripts!”

Introduction to Node.js