View Slides - Bristol Web Folk

bootlessbwakInternet and Web Development

Nov 12, 2013 (3 years and 6 months ago)

69 views

Node.js
By Duncan Angus Wilkie
Bristol Web Folk Talk Night 2
About me
Web Application Developer for the NHS
.NET
JavaScript
Integration / System Interface
Node.js
What is Node.js?
JavaScript Server-side
Built on V8 (Chrome’s JavaScript Runtime)
Node is a set of libraries build on top of V8
An Event-driven, non-blocking I/O model
Network Programming - Http, filesystem,
sockets
Working with Node.js
Node: Nodejs.org
NPM (Node Package Manager): npmjs.org
Express.js (Framework): expressjs.org
NoSQL Databases
Websites / Servers
Get files
Pull from Cache
Call Databases
Wait on connections
Most of what we do is I/O
Fetching I/O
L1 Cache: 3
L2 Cache: 14
RAM: 250
Disk: 41,000,000
Network: 240,000,000
CPU Cycles:
I/O
“We’re doing it wrong”
- Ryan Dahl (creator of node.js)
Blocking
1. Request File: ‘turtles.jpg’ (160Kb)
Wait...
Receive File: ‘turtles.jpg’
2. Request File: ‘renandstimpy.jpeg’ (13Kb)
Wait...
Receive File: ‘renandstimpy.jpeg’
3. Request File: ‘marioandluigi.jpeg’ (11Kb)
Wait...
Receive File: ‘marioandluigi.jpeg’
Web Servers
Apache
Each request spawns a new thread
Thread per connection
Threads are expensive
Takes up memory
Example: 2Mb memory per connection, 8Gb
machine === 4,000 connections
The Event Loop
Single Thread
No blocking - don’t wait!
Just give me a callback
Why JavaScript?
‘Everyone’ knows JavaScript
No pre-existing I/O
Already has the concept of an event loop
JavaScript is the new battleground of the
Browser wars
Let’s see some code
Code Examples...
Filesystem (non-blocking) //Non-Blocking
Http Server / TCP Server
Socket.io
Express.js