KEMBAR78
Build App with Nodejs - YWC Workshop | PDF
Node.js For Beginner
Kao #YWC9
Software Engineer @ jitta.com
What is Node.js
• Created by Ryan Dahl in 2009
• Server-side JavaScript
• Uses V8 is an open source JavaScript engine
developed by Google. Its
• written in C++ and is used in Google Chrome
Browser
• Event-driven with Non-blocking I/O
The Essence of Node
• JavaScript on the Server
• More than server-side JavaScript
• Fabulous framework
• Asynchronous programming
• Module-driven development
It’s is JavaScript
• Easy to learn
• Lets you unify your client/server logic
• Productivity
• Already in the Enterprise (Paypal, Netflix, Walmart,
IBM)
More than server-side
JavaScript
• Web server
• Robot controller (tessel.io)
• Command line application
• Proxy server
• Music machine
• Desktop application tooling: NW.js, Electron
Module-driven development
• Node Package Manager (NPM)
• 250,000++ total packages
• 160,000,000 downloads per day
• Simplicity
• Decoupled and reusable coding
Module-driven development
• npm focused on module-driven development
• ES6 Modules
• Module-driven development for the browser
• bower install moment —save
• npm install moment —save
Desktop Application(torrent)
Desktop Application (editor)
Game Dev Tycoon
Fabulous Framework
• Express
• Restify (for building REST API)
• Hapi (configuration-centric framework)
• Sails (fast production-ready)
• Meteor (realtime application)
Asynchronous programming
5s0s 10s
BLOCKING
5s0s 10s
NON-BLOCKING
Create node module
What is Node made of?
Event Loop
V8 JavaScript Engine
• V8 is Google's open source JavaScript engine
• V8 implements ECMAScript as specified in
ECMA-262
• V8 is written in C++ and is used in Google Chrome,
the open source browser from Google
• V8 can run standalone, or can be embedded into any
C++ application
Create Event Emitter
Stream and Buffer
Stream
• A sequence of data made available over time
Buffer
• A temporary holding spot for data being moved from
one place to another
Hello World
Buffer Buffer
Stream
Lorem ipsum dolor sit
amet, consectetur
adipisicing elit, sed do
eiusmod tempor
incididunt ut labore et
dolore magna aliqua. Ut
enim ad minim veniam,
quis nostrud exercitation
ullamco laboris nisi ut
aliquip ex ea commodo
consequat. Duis aute
irure dolor in
lowercase.txt
LOREM IPSUM DOLOR
SIT AMET,
CONSECTETUR
ADIPISICING ELIT, SED
DO EIUSMOD TEMPOR
INCIDIDUNT UT LABORE
ET DOLORE MAGNA
ALIQUA. UT ENIM AD
MINIM VENIAM, QUIS
NOSTRUD
EXERCITATION
ULLAMCO LABORIS NISI
uppercase.txt
stream
Stream
Process
Stream
roL e m
Stream
Process
Stream
Lorem
buffer
LOREM
buffer
Stream
Process
Stream
ipsum
buffer
IPSUM
buffer
Stream
Process
Stream
LOREM IPSUM
Stream
LOREM IPSUM DOLOR
SIT AMET,
CONSECTETUR
ADIPISICING ELIT, SED
DO EIUSMOD TEMPOR
INCIDIDUNT UT LABORE
ET DOLORE MAGNA
ALIQUA. UT ENIM AD
MINIM VENIAM, QUIS
NOSTRUD
EXERCITATION
ULLAMCO LABORIS NISI
uppercase.txt
What is pipe
• Connecting two streams by writing to one stream
• Let you easily read data from a source and pipe it to
a destination
Another Stream
Pipe
Process
Readable Stream
pipe
Process
Hello
Writeable Stream
Write Stream
Build App with Node
Browser
Request
Response
Web
Server
Browser
Request
Response
Web
Server
HTTP
HTTP
Browser
Request
Response
Web
Server
HTTP
HTTP
Javascript
Browser
Request
Response
Web
Server
HTTP
HTTP
Javascript
Javascript
What’s JavaScript on Server-
side
• Read and write file
• Connect with databases
• Build web server
• Asynchronous task queue/job queue
Create http server

Build App with Nodejs - YWC Workshop