node intro
TRANSCRIPT
![Page 1: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/1.jpg)
1/31 - 4%
node.jsevented I/O for V8 JavaScript
![Page 2: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/2.jpg)
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
![Page 3: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/3.jpg)
3/31 - 10%
why node?Web applications spend most of their timedoing I/O
JavaScript is the language of the web
![Page 4: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/4.jpg)
4/31 - 13%
V8
![Page 5: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/5.jpg)
5/31 - 17%
V8Google's open source JavaScript engine.
Developed by Lars Bak.
Fast: compiles JavaScript to machinecode.
Implements most of ECMAScript 5.
![Page 6: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/6.jpg)
7/31 - 23%
ECMAScript 5
![Page 7: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/7.jpg)
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]); } }});
![Page 8: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/8.jpg)
9/31 - 30%
ECMAScript 5
Access to the hidden prototypesObject.getPrototypeOf([]) // Array[].__proto__ // Array [].__proto__.__proto__ // Object
![Page 9: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/9.jpg)
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 }
![Page 10: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/10.jpg)
11/31 - 36%
node.js
![Page 11: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/11.jpg)
12/31 - 39%
node.js
Event-driven programming
Asynchronous I/O
Callbacks
![Page 12: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/12.jpg)
13/31 - 42%
node.js
Common.js module systemvar sys = require("sys");
sys.puts("hello world");
![Page 13: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/13.jpg)
14/31 - 46%
node.js
Common.js module systemrequire.paths // ["./lib", ...]__dirname // this dirname__filename // this filename
![Page 14: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/14.jpg)
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);
![Page 15: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/15.jpg)
16/31 - 52%
Event-drivenprogramming
![Page 16: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/16.jpg)
17/31 - 55%
setTimeout(function () { // Do something after 1 second}, 1000);
![Page 17: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/17.jpg)
18/31 - 59%
process.nextTick(function () { // Do something asynchronously});
![Page 18: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/18.jpg)
19/31 - 62%
Async error handlingprocess.addListener('uncaughtException', function (err) { // Handle exception });
![Page 19: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/19.jpg)
20/31 - 65%
Async signal handlingprocess.addListener('SIGINT', function (err) { // Handle Ctrl-C });
![Page 20: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/20.jpg)
21/31 - 68%
modules
![Page 21: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/21.jpg)
22/31 - 71%
file-system modulerequire('fs');
![Page 22: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/22.jpg)
23/31 - 75%
modules
fsone-to-one mapping with unix commands
most functions have a synchronousversion
![Page 23: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/23.jpg)
24/31 - 78%
Asynchronous file statfs.stat("path/to/file", function (err, res) { if (res) { // Handle success } else { // Handle error }});
![Page 24: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/24.jpg)
25/31 - 81%
Synchronous file statvar res = fs.statSync("path/to/file");
if (res) { // Handle success } else { // Handle error }
![Page 25: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/25.jpg)
29/31 - 94%
http://nodejs.org
![Page 26: Node intro](https://reader033.vdocuments.us/reader033/viewer/2022052321/55512c15b4c905b3598b4b9c/html5/thumbnails/26.jpg)
30/31 - 97%
@cloudheadAlexis Sellier
http://github.com/cloudhead/node-intro