Upload
cloudhead
View
2.584
Download
1
Tags:
Embed Size (px)
Citation preview
1/31 - 4%
node.jsevented I/O for V8 JavaScript
2/31 - 7%
what is node?Server-side JavaScript done right.
Runs on V8
An environment for developing high-performance web services
Evented TCP stack
Not a framework
3/31 - 10%
why node?Web applications spend most of their timedoing I/O
JavaScript is the language of the web
4/31 - 13%
V8
5/31 - 17%
V8Google's open source JavaScript engine.
Developed by Lars Bak.
Fast: compiles JavaScript to machinecode.
Implements most of ECMAScript 5.
7/31 - 23%
ECMAScript 5
8/31 - 26%
ECMAScript 5
Safe prototype extensionObject.defineProperty(Object.prototype, "forEach", { value: function (callback) { var keys = Object.keys(this);
for (var i = 0, key; i < keys.length; i++) { key = keys[i]; callback.call(this, key, this[key]); } }});
9/31 - 30%
ECMAScript 5
Access to the hidden prototypesObject.getPrototypeOf([]) // Array[].__proto__ // Array [].__proto__.__proto__ // Object
10/31 - 33%
ECMAScript 5
Basic prototypal inheritancevar o = Object.create({ foo: 42 });
o.bar = "bah";
Object.keys(o) // ["bar"]
o.foo // 42o.__proto__ // { foo: 42 }
11/31 - 36%
node.js
12/31 - 39%
node.js
Event-driven programming
Asynchronous I/O
Callbacks
13/31 - 42%
node.js
Common.js module systemvar sys = require("sys");
sys.puts("hello world");
14/31 - 46%
node.js
Common.js module systemrequire.paths // ["./lib", ...]__dirname // this dirname__filename // this filename
15/31 - 49%
node.js
Simple HTTP servervar http = require('http');
http.createServer(function (request, response) { response.writeHead(200, { 'Content-Type':'text/plain' }); response.end('Hello World\n');}).listen(8000);
16/31 - 52%
Event-drivenprogramming
17/31 - 55%
setTimeout(function () { // Do something after 1 second}, 1000);
18/31 - 59%
process.nextTick(function () { // Do something asynchronously});
19/31 - 62%
Async error handlingprocess.addListener('uncaughtException', function (err) { // Handle exception });
20/31 - 65%
Async signal handlingprocess.addListener('SIGINT', function (err) { // Handle Ctrl-C });
21/31 - 68%
modules
22/31 - 71%
file-system modulerequire('fs');
23/31 - 75%
modules
fsone-to-one mapping with unix commands
most functions have a synchronousversion
24/31 - 78%
Asynchronous file statfs.stat("path/to/file", function (err, res) { if (res) { // Handle success } else { // Handle error }});
25/31 - 81%
Synchronous file statvar res = fs.statSync("path/to/file");
if (res) { // Handle success } else { // Handle error }
29/31 - 94%
http://nodejs.org
30/31 - 97%
@cloudheadAlexis Sellier
http://github.com/cloudhead/node-intro