node.js introduction

24
node.js introduction of server side javascript Saturday, November 23, 13

Upload: sira-sujjinanont

Post on 28-Jan-2015

7.232 views

Category:

Technology


3 download

DESCRIPTION

in Joomladay 2013 Bangkok

TRANSCRIPT

Page 1: Node.js Introduction

node.jsintroduction of server side javascript

Saturday, November 23, 13

Page 2: Node.js Introduction

Sira Sujjinanont@hunt

Managing DirectorWebiz Co.,Ltd.

CTO Jitta.com

15 years inWeb development

Saturday, November 23, 13

Page 3: Node.js Introduction

Web Development Journey

• Static HTML

• PERL/CGI (2 years)

• PHP (11 years)

• CMS > Drupal, Wordpress, Joomla

• Framework > Yii, Zend, CodeIgniter, …

• What’s next?!?

Saturday, November 23, 13

Page 4: Node.js Introduction

PHP bad parts

• Consume a lot of memories

• Cannot do Realtime Application

• Cannot deal direct with protocol layer

• No parallel processing

Saturday, November 23, 13

Page 5: Node.js Introduction

What I need in the next?

• Easy to learn (for me and for my team)

• Fast / Scalability

• Allow us to dig deep in engineering

• New technology! New boundary!

• Open source with great community

Saturday, November 23, 13

Page 6: Node.js Introduction

And node.js came up!(server-side javascript)

but we need to dig it deep!!

Saturday, November 23, 13

Page 7: Node.js Introduction

Why Javascript?

• Easy to learn and understanding!

• Front-end coder can do backend immediately!

• Javascript Engine war!(huge changed on web industry)

• Non-blocking I/O

• One language on both front and back!!!

Saturday, November 23, 13

Page 8: Node.js Introduction

Server-side javascript

• Netscape LiveWrite 1996

• Rhino 1997

• and over 50 platforms!

Saturday, November 23, 13

Page 9: Node.js Introduction

Many problems!

• Slow engines

• Lag of interest in Javascript language(until 2005… ajax trend!)

• Great competitors platform and language

Saturday, November 23, 13

Page 10: Node.js Introduction

• Created by Ryan Dahl in 2009easily building fast, scalable network applications

• Google V8 Javascript Engine(Same technology in Google Chrome)

• NPM Package Manager(Come by default great as it should be: 48,362 modules)

• Realtime, Command line, Many tools

Saturday, November 23, 13

Page 11: Node.js Introduction

When do we need a web?

• Download web server and install

• Install PHP and maybe database

• Configuration….

• And now we can put our code on it!

Saturday, November 23, 13

Page 12: Node.js Introduction

var http = require('http');http.createServer(function (req, res) { res.writeHead(200); res.end("Hello World!\n");}).listen(3000);console.log('Server running at http://localhost:3000/');

See Node.js way!(create a web server, just in 6 lines of code)

2

1 Download and click installapt-get install nodejs

Saturday, November 23, 13

Page 13: Node.js Introduction

var http = require('http');http.createServer(function (req, res) { res.writeHead(200); res.end("Hello World!\n");}).listen(3000);console.log('Server running at http://localhost:3000/');

It just works!Web server and ready fora huge traffic :)

even 10,000/reqs

Saturday, November 23, 13

Page 14: Node.js Introduction

var a = db.query(“SELECT * FROM users”);console.log(‘Result a:’, a);

var b = db.query(“SELECT * FROM documents”);console.log(‘Result B:’, b);

Blocking I/O

Saturday, November 23, 13

Page 15: Node.js Introduction

var a = db.query(“SELECT * FROM users”);console.log(‘Result a:’, a);

var b = db.query(“SELECT * FROM documents”);console.log(‘Result B:’, b);

Blocking I/O

wait

wait

Waste cpu cycles from waiting…other part of code, they need to wait too!

Saturday, November 23, 13

Page 16: Node.js Introduction

var a = db.query(“SELECT * FROM users”);console.log(‘Result a:’, a);

var b = db.query(“SELECT * FROM documents”);console.log(‘Result B:’, b);

Blocking I/O

sum ( a + b)

wait

wait

Saturday, November 23, 13

Page 17: Node.js Introduction

var a = db.query(“SELECT * FROM users”, function(result){ console.log(‘Result a:’, a); });

var b = db.query(“SELECT * FROM documents”, function(result){ console.log(‘Result b:’, ab); });

Non Blocking I/O

Saturday, November 23, 13

Page 18: Node.js Introduction

var a = db.query(“SELECT * FROM users”, function(result){ console.log(‘Result a:’, a); });

var b = db.query(“SELECT * FROM documents”, function(result){ console.log(‘Result b:’, ab); });

Non Blocking I/O

max ( a, b )

run parallel

run parallel

Saturday, November 23, 13

Page 19: Node.js Introduction

Benchmark

nginx (non blocking i/o) apache (blocking i/o)

Saturday, November 23, 13

Page 20: Node.js Introduction

Suitable Applications• Single page app

• Full web app

• Realtime appchat, notification, games

• Crawler, Bot

• Streaming

• File uploading

Saturday, November 23, 13

Page 21: Node.js Introduction

Who using now?

and thousand thousand more…including me... Molome ....

Saturday, November 23, 13

Page 22: Node.js Introduction

You should try!

• It’s not hard to start if you familiar with Javascript

• If you looking for another language

• It’ll change the way you do a web

• And it’s FUN!!

Saturday, November 23, 13

Page 23: Node.js Introduction

Start now!http://github.com/hunt/seventiestemplate for node.js web applicationby me!

https://github.com/jlleblanc/nodejs-joomlamodule for Joomla

Saturday, November 23, 13

Page 24: Node.js Introduction

Q&AFree to ask!

Saturday, November 23, 13