Node.JS - Blurring the Line Between Client and Server var title = “ Node.JS - Blurring the Line Between Client and Server ”; $(this).attr(“title”, title);

Slides:



Advertisements
Similar presentations
SIP Servlets. SIP Summit SIP Servlets Problem Statement Want to enable construction of a wide variety of IP telephony.
Advertisements

Game Server Development in node.js
Microsoft Confidential. An incubation effort to: Support client -> server communication in native code with a modern C++ API design Support writing Azure-based.
Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet
Data Freeway : Scaling Out to Realtime Author: Eric Hwang, Sam Rash Speaker : Haiping Wang
Gevent network library Denis Bilenko gevent.org. Problem statement from urllib2 import urlopen response = urlopen(' body = response.read()
Tornado Web and MongoDB An Introduction to AsyncMongo MongoBoston John C. Zablocki Development Manager, HealthcareSource Organizer, Beantown.
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Intel Do-It-Yourself Challenge node.js
Internet of Things with Intel Edison Web controller
By: Craig Hecock.  A JavaScript runtime environment running Google Chrome’s V8 engine ◦ a.k.a. a server-side solution for JS ◦ Compiles JS, making it.
© 2014 IBM Corporation Empowering the IBM ecosystem Introduction to Developing applications using node.js on Bluemix IBM Ecosystem Development Instructors.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Nov 23, 2014 Sofia var title = “Title Here, 36pt, Segoe UI”; var info = { name: “Author”, otherOptional: “Info” };
Lecture 8 Epidemic communication, Server implementation.
JavaScript Event Loop Not yo mama’s multithreaded approach. slidesha.re/ZPC2nD.
Interesting facts about node.js.  Asynchronous I/O  How do they do that?..threads (usually) What do Web Servers do?
 A JavaScript runtime environment running Google Chrome’s V8 engine ◦ a.k.a. a server-side solution for JS ◦ Compiles JS, making it really fast  Runs.
Cooperative Task Management without Manual Stack Management Or, Event-driven Programming is not the Opposite of Thread Programming Atul Adya, John Howell,
Applets & Servlets.
App Windows UI object Windows object App code Windows object.
Ole Erecius Tirsdag den 9. juni Programming is always at The EDGE !!!
Node.js - What is Node.js? -
1 Accelerated Web Development Course JavaScript and Client side programming Day 2 Rich Roth On The Net
Chapter 8 Cookies And Security JavaScript, Third Edition.
Orbited Scaling Bi-directional web applications A presentation by Michael Carter
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Concurrency Patterns Emery Berger and Mark Corner University.
Server to Server Communication Redis as an enabler Orion Free
CS333 Intro to Operating Systems Jonathan Walpole.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Zz SOCKET.IO going real time with Arnout Kazemier
Chat Room App Logan Linn Network Application Design Fall 2010.
PHP Performance w/APC + thaicyberpoint.com thaithinkpad.com thaihi5.com.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
Node.Js 1. 2 Contents About Node.Js Web requirement latest trends Introduction Simple web server creation in Node.Js Dynamic Web pages Dynamic web page.
Code Development for High Performance Servers Topics Multithreaded Servers Event Driven Servers Example - Game Server code (Quake) A parallelization exercise.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Aniruddha Deswandikar & Govind Kanshi Microsoft Technology Center, Bangalore SESSION CODE: ##### Building performant Web applications.
Node.JS introduction. What is Node.JS? v8 JavaScript runtime Event driven Non-blocking standard libraries Most APIs speak streams Provides a package manager.
Concurrent TCP servers. The basic idea 1 client = 1 task. The task is alive as long until the connection is closed The task closes the connection.
Configuring SQL Server for a successful SharePoint Server Deployment Haaron Gonzalez Solution Architect & Consultant Microsoft MVP SharePoint Server
Introduction to Node.js® Jitendra Kumar Patel Saturday, January 31, 2015.
Ur/Web: A Simple Model for Programming the Web
Lean With MEAN.
NodeJS and MEAN cs6320.
Node.Js Server Side Javascript
Physics validation database
The Server-side JavaScript
Node.js Express Web Applications
CSE 775 – Distributed Objects Submitted by: Arpit Kothari
NodeJS and MEAN Prof. L. Grewe.
CS399 New Beginnings Jonathan Walpole.
Async or Parallel? No they aren’t the same thing!
3 Things Everyone Knows About Node JS That You Don't
Node.Js Server Side Javascript
2017, Fall Pusan National University Ki-Joune Li
12 Asynchronous Programming
CSE 154 Lecture 22: AJAX.
The Single Node B-tree for Highly Concurrent Distributed Data Structures by Barbara Hohlt 11/23/2018.
Nathan Totten Technical Evangelist Windows Azure
Building responsive apps and sites with HTML5 web workers
Web Programming Language
var title = “Title Here, 36pt, Segoe UI”;
INTRODUCTION TO By Stepan Vardanyan.
Week 01 Node.js Week 01
Lecture 11: Node.JS February 16, 2018 Open twitter page, sphere-e page
PHP an introduction.
Week 02 Node.js Week 02
Introduction.
Presentation transcript:

Node.JS - Blurring the Line Between Client and Server var title = “ Node.JS - Blurring the Line Between Client and Server ”; $(this).attr(“title”, title); $(this).data({ font: ‘Segoe UI’, size: ‘30pt’, maxLines: ‘3 lines max’ });

Agenda Why Node.JS? o Why yet another server framework? What is it? o Asynchronous IO and the Evented Model Hands On o Let’s write some code o How to node o Package, frameworks and tools o Latest features Q&A

JavaScript on the Server Pros It’s JavaScript – it’s the best! It’s fast and easy to scale One language to rule them all o Share code across client/server o Never write serialization code again – it’s all JSON Never debug multithreaded code again More? Cons It’s JavaScript – is it even a real language? Async programming – can be unfamiliar and hard Nested callback hell Single process doesn’t scale across cores More?

ORIGINS Why yet another server framework?

Evolution of Socket Servers In the beginning was CGI o A new process per request Worker Pool Model o Dispatch requests to persistent worker pool To infinity and beyond o The C10k problem o The race for high throughput and low latency

Thread Pool Model responsesrequest queue thread pool thread 1 thread 2 thread 3 thread 4 thread n concurrency = # threads

Worker Thread Efficiency wait… route, parse request form db query parse db result form web service query process results form response db queryweb service query log to disk wait…

Relative I/O Latency CPU cycles L1 cache3 L2 cache14 RAM250 disk network Relative next room ~5m across the street ~20m next block ~400m Earth circumference distance to the Moon

IS THERE A BETTER WAY?

Asynchronous I/O 1.Start I/O and return (non-blocking) 2.Perform other tasks 3.When I/O completes, process the result Handle requests in a single thread Popular examples: nginx, lighttpd

Node.JS in 5 words Evented I/O for V8 JavaScript

Evented Model event queue event loop single-thread user space I/O done network file system other internal thread pool

Async Callbacks – Look Familiar? setTimeout(function() { console.log("time's up") }, 1000); console.log('hello') while (true) {}

HANDS ON Let’s write some code

“Hello, World!” var http = require('http') http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}) res.end("hello\n") }).listen(9090)

Static HTTP Server var http = require('http') var fs = require('fs') http.createServer(function(req, res) { fs.readFile('index.html', function(err, data) { if (err) { res.writeHead(500) res.end() } else { res.end(data) } }) }).listen(9090)

Let’s code Writing a simple blog

Module System base64.js var encoding = 'base64‘ // locals are private exports.toBase64 = function(s) { return new Buffer(s).toString(encoding) } app.js var b64 = require('./base64') var a = b64.toBase64('JQueryBulgaria')

Error Handling Asynchronous Callbacks and Exceptions Dude, where is my stack? Cannot debug across event loop iterations Async callback error code convention First callback parameter is error object fs.readFile(path, function(err, file) { if (err) { // handle error } //... })

“Do, or do not. There is no try.” Reconsider the conventional wisdom of exception handling Exceptions are cleaner, more elegant and… wrong Hidden control flow and Corrupt State Just because you don’t see a code path doesn’t mean it doesn’t exist New generation of languages shun exceptions (like Go)

Callback Hell – the Modern GOTO

Avoiding The Callback Pyramid of Doom Keep it shallow Name your anonymous functions Avoid nesting Use a functional programming helper module async, underscore (both server and client) Other alternatives Promises Fibers

Web App Frameworks Node.JS is powerful o Full control over HTTP server o But most of the time you’ll use a web framework Web App Frameworks like ExpressJS provide: o Routing o Body parsing o Session and Cookie Management o Templating o Static File Server, Logger and many more

ExpressJS – Hit Counter var express = require('express') var app = express(); app.use(express.cookieParser()); app.use(express.cookieSession({secret: "dG9wc2VjcmV0"})); app.use(function(req, res) { var sess = req.session sess.hits = sess.hits || 0 sess.hits++ res.json({ visits: sess.hits }) }); app.listen(80)

Questions? res.setHeader(“Content-Type”, “text/plain”) res.end(“Bye!”)

Thanks to our Sponsors: Diamond Sponsor: Gold Sponsors: Swag Sponsors:Media Partners: Technological Partners: Silver Sponsors: Bronze Partners: