Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Node and its Core Modules
Search
aryoung
February 06, 2013
Programming
3
260
Introduction to Node and its Core Modules
From
http://bathcamp.org/
, February 6th 2013
aryoung
February 06, 2013
Tweet
Share
More Decks by aryoung
See All by aryoung
Vim and the Web
aryoung
0
7.8k
Tern for Vim
aryoung
2
1.6k
Vim London: Custom Motions
aryoung
6
3.5k
Other Decks in Programming
See All in Programming
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
Go の GC の不得意な部分を克服したい
taiyow
3
780
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
2
220
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
Jakarta EE meets AI
ivargrimstad
0
240
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Building an army of robots
kneath
302
44k
Code Review Best Practice
trishagee
65
17k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
A Modern Web Designer's Workflow
chriscoyier
693
190k
For a Future-Friendly Web
brad_frost
175
9.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Documentation Writing (for coders)
carmenintech
66
4.5k
A Tale of Four Properties
chriscoyier
157
23k
Transcript
Introduction to Node Alex
Overview ‣ Brief
5 Years Ago... ‣ We
Thursday, 7 February 13
A
Node’s Strengths ‣ Network-oriented
Installation ‣ Wizards
Runtime Environment ‣ Every
Modules ‣ CommonJS
Core Modules ‣ Events,
"Node's
Why Bother? ‣ Events/streams
Streams var zlib = require('zlib').createGzip(); var fs = require('fs'); var
inp = fs.createReadStream('input.txt'); var out = fs.createWriteStream('output.txt.gz'); inp.pipe(gzip).pipe(out); Clean,
Events var util = require('util'); var events = require('events'); function
Player() { events.EventEmitter.call(this); } util.inherits(Player, events.EventEmitter); var player = new Player(); player.on('play', function(track) { console.log('[NP]:', track.title); }); player.emit('play', { title: 'Spit On A Stranger', artist: 'Pavement' }); Thursday, 7 February 13
Servers var net = require('net'); var server = net.createServer(function(c) {
console.log('server connected'); c.on('end', function() { console.log('server disconnected'); }); c.write('hello\r\n'); c.pipe(c); }); server.listen(8124, function() { //'listening' listener console.log('server bound'); }); Thursday, 7 February 13
HTTP Server var http = require('http'); var fs = require('fs');
http.createServer(function(req, res) { fs.readFile(__dirname + 'index.html', function(err, data) { if (err) { res.statusCode = 500; res.end(String(err)); } else { res.end(data); } }); }).listen(8000); Thursday, 7 February 13
HTTP Server var http = require('http'); var fs = require('fs');
http.createServer(function(req, res) { fs.readFile(__dirname + 'index.html', function(err, data) { if (err) { res.statusCode = 500; res.end(String(err)); } else { res.end(data); } }); }).listen(8000); Thursday, 7 February 13
HTTP Server var http = require('http'); var fs = require('fs');
http.createServer(function(req, res) { fs.readFile(__dirname + 'index.html', function(err, data) { if (err) { res.statusCode = 500; res.end(String(err)); } else { res.end(data); } }); }).listen(8000); Thursday, 7 February 13
HTTP Server var http = require('http'); var fs = require('fs');
http.createServer(function(req, res) { fs.readFile(__dirname + 'index.html', function(err, data) { if (err) { res.statusCode = 500; res.end(String(err)); } else { res.end(data); } }); }).listen(8000); Not
Streams with HTTP var http = require('http'); var fs =
require('fs'); http.createServer(function(req, res) { var stream = fs.createReadStream('index.html'); stream.pipe(res); }).listen(8000); Thursday, 7 February 13
Gzip for Free var http = require('http'); var fs =
require('fs'); var zlib = require('zlib'); http.createServer(function(req, res) { var stream = fs.createReadStream('index.html'); res.writeHead(200, { 'content-encoding': 'gzip' }); stream.pipe(zlib.createGzip()).pipe(res); }).listen(8000); Thursday, 7 February 13
Gzip for Free var http = require('http'); var fs =
require('fs'); var zlib = require('zlib'); http.createServer(function(req, res) { var stream = fs.createReadStream('index.html'); res.writeHead(200, { 'content-encoding': 'gzip' }); stream.pipe(zlib.createGzip()).pipe(res); }).listen(8000); How
TO-DO: Learn
The End http://www.flickr.com/photos/dunechaser/6884829633/ Thursday, 7 February 13