Top Banner
Node.js For Beginner Sarunyhot Suvannachoti (Kao) Software Engineer @ Jitta.com
32

Node.js for beginner

Apr 13, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Node.js for beginner

Node.js For Beginner

Sarunyhot Suvannachoti (Kao) Software Engineer @ Jitta.com

Page 2: Node.js for beginner

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

• Single threaded

• Current Version is 4.0.0

Page 3: Node.js for beginner

Node.js Foundation

Fork of Node.js

+

Page 4: Node.js for beginner

Node.js Event loop

Page 5: Node.js for beginner

Blocking I/O

Page 6: Node.js for beginner

Blocking I/O

10 Sec

30 Sec

Page 7: Node.js for beginner

Blocking I/O

30 Sec

10 Sec

Sum = 30 + 10

Page 8: Node.js for beginner

Non-Blocking I/O

Page 9: Node.js for beginner

Non-Blocking I/O

Run parallel

min=10 max=30

Page 10: Node.js for beginner

Asynchronous programming techniques

Page 11: Node.js for beginner

The two model of Async Processing

• Callback function generally define logic for one-off responses. – Ex: perform a database query

• Event listeners, are essentially callbacks that are associated with a conceptual entity (an event). – Respond to repeating events – EX: HTTP server emits a request event when an HTTP request is made

Page 12: Node.js for beginner

What is callback function?

• A callback is a function, passed as an argument to an asynchronous function

• It describes what to do after the asynchronous operation has completed

Callback function

Page 13: Node.js for beginner

What is event-listeners?

Page 14: Node.js for beginner

What is event-listeners?

Page 15: Node.js for beginner

Stream

Page 16: Node.js for beginner

When to use Node.js?

• Creating streaming based real- time services, web chat applications, static file servers etc.

• Applications that have a lot of concurrent connections and each request only needs very few CPU cycles

Page 17: Node.js for beginner

The Essence of Node

• JavaScript on the Server

• More than server-side JavaScript

• Fabulous framework

• Asynchronous programming

• Module-driven development

Page 18: Node.js for beginner

It’s is JavaScript

• Easy to learn

• Lets you unify your client/server logic

• Productivity

• Already in the Enterprise (Paypal, Netflix, Walmart, IBM)

Page 19: Node.js for beginner

More than server-side JavaScript

• Web server

• Robot controller (tessel.io)

• Command line application

• Proxy server

• Music machine

• Desktop application tooling: NW.js

Page 20: Node.js for beginner

Desktop Application (torrent)

Page 21: Node.js for beginner

Desktop Application (editor)

Page 22: Node.js for beginner

Desktop Application (music)

Page 23: Node.js for beginner

Desktop Application (game)

Page 24: Node.js for beginner

Fabulous framework

• Express

• Restify (for building REST APIs, automatic DTrace support)

• Hapi (configuration-centric framework)

• Sails (fast production-ready)

• Meteor (realtime application)

Page 25: Node.js for beginner

Module-driven development

• Node Package Manager (NPM)

• 180,000++ packages

• 90,000,000++ downloads per day

• Simplicity

• Decoupled and reusable coding

Page 26: Node.js for beginner
Page 27: Node.js for beginner
Page 28: Node.js for beginner

The state of the registry

• 1400MM package downloads last month

• 150,000 packages in the registry

• `Node` is moving faster than `Node.js`

Page 29: Node.js for beginner

Module-driven development

• npm focused on module-driven development

• ES6 Modules

• Module-driven development for the browser

• Browser tools: Browserify

Page 30: Node.js for beginner

Module-driven development for the browser

bower install moment --save npm install moment --save

Page 31: Node.js for beginner

DEMO

Page 32: Node.js for beginner

Where can learn more?

• http://nodeschool.io

• http://www.codewars.com

• https://www.codeschool.com/courses/real-time-web-with-node-js

• http://nodeup.com/