SlideShare a Scribd company logo
1 of 33
Download to read offline
Disclaimer ;-)
Doesn't necessarily reflect the views of IBM, or any of
my Node.js collaborators...
1
nextTick
•  [ ] in next tick of the event loop
•  [ ] immediately after A returns
2
process.nextTick(function() {
// Called ...
});
nextTick
•  [ ] in next tick of the event loop
•  [x] immediately after A returns
3
process.nextTick(function() {
// Called ...
});
setImmediate
•  [ ] in next tick of the event loop
•  [ ] immediately after A returns
4
setImmediate(function() {
// Called ...
});
setImmediate
•  [x] in next tick of the event loop
•  [ ] immediately after A returns
5
setImmediate(function() {
// Called ...
});
nextTick vs setImmediate
•  nextTick: adds callback to queue to be called immediately
•  setImmediate: adds callback to queue to be called next tick
6
worker.kill()
7
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.kill('SIGHUP');
})
.on('exit', function() {
console.log('Exit');
});
} else {
process.on('SIGHUP', function() {
console.log('Hup');
});
}
worker.kill()
•  [ ] "Hup"
•  [ ] "Exit"
•  [ ] "Hup" and "Exit"
•  [ ] No output
8
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.kill('SIGHUP');
})
.on('exit', function() { console.log('Exit'); });
} else {
process.on('SIGHUP', function() { console.log('Hup'); });
}
worker.kill()
•  [ ] "Hup"
•  [x] "Exit"
•  [ ] "Hup" and "Exit"
•  [ ] No output
9
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.kill('SIGHUP');
})
.on('exit', function() { console.log('Exit'); });
} else {
process.on('SIGHUP', function() { console.log('Hup'); });
}
worker.kill() - what is it really?
•  Use worker.process.kill() if you want to signal the worker
•  Asymetric with worker.send(), worker.on('message', ...), etc.
10
Worker.prototype.kill = function(signo) {
var proc = this.process;
this.once('disconnect', function() {
this.process.kill(signo || 'SIGTERM');
});
this.disconnect();
};
worker.suicide - kill the worker
•  [ ] true
•  [ ] false
11
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.kill('SIGTERM');
})
.on('exit', function() {
// this.suicide is ....
});
} else {
}
worker.suicide - kill the worker
•  [x] true
•  [ ] false
12
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('online', function() {
this.kill('SIGTERM');
})
.on('exit', function() {
// this.suicide is ....
});
} else {
}
worker.suicide - exit the worker
•  [ ] true
•  [ ] false
13
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('exit', function() {
// this.suicide is ....
});
} else {
process.exit(0);
}
worker.suicide - exit the worker
•  [ ] true
•  [x] false
14
var cluster = require('cluster');
if (cluster.isMaster) {
cluster.fork()
.on('exit', function() {
// this.suicide is ....
});
} else {
process.exit(0);
}
worker.suicide - what does it mean?
•  worker.disconnect() in parent (implicitly done by worker.kill())
•  process.disconnect() in worker
15
Actual meaning: "orderly exit"
url.parse/format
16
var url = require('url');
var uri = url.parse('http://example.com:8080/path');
uri.host = 'ibm.com';
console.log(url.format(uri));
•  [ ] yes
•  [ ] no
Prints http://ibm.com:8080/path ...
url.parse/format
17
var url = require('url');
var uri = url.parse('http://example.com:8080/path');
uri.host = 'ibm.com';
console.log(url.format(uri));
•  [ ] yes
•  [x] no: http://ibm.com/path
Prints http://ibm.com:8080/path ...
url.parse/format
•  host is "example.com:8080"
•  hostname is "example.com"
18
url.parse/format
19
var url = require('url');
var uri = url.parse('http://example.com:8080/path');
uri.hostname = 'ibm.com';
console.log(url.format(uri));
•  [ ] yes
•  [ ] no
Prints http://ibm.com:8080/path ...
url.parse/format
20
var url = require('url');
var uri = url.parse('http://example.com:8080/path');
uri.hostname = 'ibm.com';
console.log(url.format(uri));
•  [ ] yes
•  [x] no: http://example.com:8080/path
Prints http://ibm.com:8080/path ...
url.parse/format
•  hostname and port are ignored if host is present...
21
url.parse/format
22
var url = require('url');
var uri = url.parse('http://example.com:8080/path');
delete uri.host;
uri.hostname = 'ibm.com';
console.log(url.format(uri));
•  http://ibm.com:8080/path, finally!
url.parse/format
•  parse: "http://example:8080":
– port is 8080
– host is "example:8080"... why not hostport?
– hostname is "example"... why not host?
•  format: hostname and port are ignored if hostname is present
– shouldn't they be prefered if present?
23
path.parse/format
24
var path = require('path');
var bits = path.parse('some/dir/index.txt');
// has: .name, .ext
bits.ext = '.html';
console.log(path.format(bits));
Logs some/dir/index.html...
•  [ ] yes
•  [ ] no
path.parse/format
25
var path = require('path');
var bits = path.parse('some/dir/index.txt');
bits.ext = '.html';
console.log(path.format(bits));
Logs some/dir/index.html...
•  [ ] yes
•  [x] no: some/dir/index.txt
path.parse/format
26
var path = require('path');
var bits = path.parse('some/dir/index.txt');
console.log(bits.base); // > index.txt
delete bits.base
bits.ext = '.html';
console.log(path.format(bits));
Logs some/dir/index.html...
•  [ ] yes
•  [ ] no
Its probably like url...
path.parse/format
27
var path = require('path');
var bits = path.parse('some/dir/index.txt');
console.log(bits.base); // > index.txt
delete bits.base
bits.ext = '.html';
console.log(path.format(bits));
Logs some/dir/index.html...
•  [ ] yes
•  [x] no: some/dir/
path.parse/format
28
var path = require('path');
var bits = path.parse('some/dir/index.txt');
bits.base = bits.name + '.html';
console.log(path.format(bits)); // > some/dir/index.html
Its just completely different, format always ignores name and ext.
Correct:
streams v1, 2, 3
29
Note that, for backwards compatibility reasons, removing 'data' event
handlers will not automatically pause the stream. Also, if there are
piped destinations, then calling pause() will not guarantee that the
stream will remain paused once those destinations drain and ask for
more data.
From https://nodejs.org/api/stream.html#stream_class_stream_readable:
streams v1, 2, 3
30
Note that, for backwards compatibility reasons, removing 'data' event
handlers will not automatically pause the stream. Also, if there are
piped destinations, then calling pause() will not guarantee that the
stream will remain paused once those destinations drain and ask for
more data.
From https://nodejs.org/api/stream.html#stream_class_stream_readable:
When can we delete backwards compat to v0.8?
Question
•  Laurie Voss (@seldo), NPM, Nov. 28, 2015
31
What kind of node do you want: a good one?
or a (mostly) v0.8 compatible one?
@octetcloud As of right now, 30.4% of registered npm
accounts are less than 6 months old.
Answer
•  github, twitter, etc..
•  Be tolerant (or intolerant) of breakages, but what
you say will effect what happens.
32
Its yours (and a lot of other people's) Node.js, speak out:
Flames to:
•  github: @sam-github
•  email: rsam@ca.ibm.com
•  twitter: @octetcloud
•  talk source: https://gist.github.com/sam-github/4c5c019b92cf95fb6571, or
https://goo.gl/2RWpqE
33

More Related Content

What's hot

Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Sergey Platonov
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The LandingHaci Murat Yaman
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...DevGAMM Conference
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовYandex
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Platonov Sergey
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6fisher.w.y
 
20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugs20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugsComputer Science Club
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part iiJonah Marrs
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugsComputer Science Club
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival GuideGiordano Scalzo
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding classJonah Marrs
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
 
NSOperation objective-c
NSOperation objective-cNSOperation objective-c
NSOperation objective-cPavel Albitsky
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介Akira Maruoka
 

What's hot (20)

Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The Landing
 
Groovy
GroovyGroovy
Groovy
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
 
20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugs20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugs
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Lenses
LensesLenses
Lenses
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
NSOperation objective-c
NSOperation objective-cNSOperation objective-c
NSOperation objective-c
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
 

Viewers also liked

Aporte Pastoral. Adviento 2015. Año de la Misericordia
Aporte Pastoral. Adviento 2015. Año de la MisericordiaAporte Pastoral. Adviento 2015. Año de la Misericordia
Aporte Pastoral. Adviento 2015. Año de la MisericordiaPastoral Social de Monterrey
 
New blank document
New blank documentNew blank document
New blank documentSadiq Vali
 
Fixflo Scottish Property Technology Roadshow Slides
Fixflo Scottish Property Technology Roadshow SlidesFixflo Scottish Property Technology Roadshow Slides
Fixflo Scottish Property Technology Roadshow SlidesSamuel Oliver Zawadzki
 
Resumen de nulidad y simulacion
Resumen de nulidad y simulacionResumen de nulidad y simulacion
Resumen de nulidad y simulacionnataliaisabella
 
международный университет (2)
международный университет (2)международный университет (2)
международный университет (2)Ayday Maxatbekova
 
Understanding the Single Thread Event Loop
Understanding the Single Thread Event LoopUnderstanding the Single Thread Event Loop
Understanding the Single Thread Event LoopTorontoNodeJS
 
Open Culture - How Wiki loves art and data - Packed
 Open Culture - How Wiki loves art and data - Packed Open Culture - How Wiki loves art and data - Packed
Open Culture - How Wiki loves art and data - PackedOpen Knowledge Belgium
 
Estrategias de Prevención y manejo de la agresión escolar
Estrategias de Prevención y manejo de la agresión escolar Estrategias de Prevención y manejo de la agresión escolar
Estrategias de Prevención y manejo de la agresión escolar Red PaPaz
 

Viewers also liked (13)

Aporte Pastoral. Adviento 2015. Año de la Misericordia
Aporte Pastoral. Adviento 2015. Año de la MisericordiaAporte Pastoral. Adviento 2015. Año de la Misericordia
Aporte Pastoral. Adviento 2015. Año de la Misericordia
 
Apply Property 2016 Roadshow Slides
Apply Property 2016 Roadshow Slides Apply Property 2016 Roadshow Slides
Apply Property 2016 Roadshow Slides
 
New blank document
New blank documentNew blank document
New blank document
 
Fixflo Scottish Property Technology Roadshow Slides
Fixflo Scottish Property Technology Roadshow SlidesFixflo Scottish Property Technology Roadshow Slides
Fixflo Scottish Property Technology Roadshow Slides
 
Colegio 2
Colegio 2Colegio 2
Colegio 2
 
Resumen de nulidad y simulacion
Resumen de nulidad y simulacionResumen de nulidad y simulacion
Resumen de nulidad y simulacion
 
Open Data: What’s Next?
Open Data: What’s Next?Open Data: What’s Next?
Open Data: What’s Next?
 
международный университет (2)
международный университет (2)международный университет (2)
международный университет (2)
 
PRESENTACION ACEBRON
PRESENTACION ACEBRONPRESENTACION ACEBRON
PRESENTACION ACEBRON
 
mohamed morsy_CV
mohamed morsy_CVmohamed morsy_CV
mohamed morsy_CV
 
Understanding the Single Thread Event Loop
Understanding the Single Thread Event LoopUnderstanding the Single Thread Event Loop
Understanding the Single Thread Event Loop
 
Open Culture - How Wiki loves art and data - Packed
 Open Culture - How Wiki loves art and data - Packed Open Culture - How Wiki loves art and data - Packed
Open Culture - How Wiki loves art and data - Packed
 
Estrategias de Prevención y manejo de la agresión escolar
Estrategias de Prevención y manejo de la agresión escolar Estrategias de Prevención y manejo de la agresión escolar
Estrategias de Prevención y manejo de la agresión escolar
 

Similar to Node.js API pitfalls

Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?jonbodner
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityBrendan Gregg
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6scuhurricane
 
groovy databases
groovy databasesgroovy databases
groovy databasesPaul King
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsBaruch Sadogursky
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuerysergioafp
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensNETWAYS
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Charles Nutter
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: ServersidenessWebExpo
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitVaclav Pech
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicGraham Dumpleton
 
Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicNew Relic
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeAijaz Ansari
 

Similar to Node.js API pitfalls (20)

Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
Javascript
JavascriptJavascript
Javascript
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Advanced jQuery
Advanced jQueryAdvanced jQuery
Advanced jQuery
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet Mens
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
Douglas Crockford: Serversideness
Douglas Crockford: ServersidenessDouglas Crockford: Serversideness
Douglas Crockford: Serversideness
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New Relic
 
Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New Relic
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCode
 

More from TorontoNodeJS

Safely Build, Publish & Maintain ES2015, ES2016 Packages Today
Safely Build, Publish & Maintain ES2015, ES2016 Packages TodaySafely Build, Publish & Maintain ES2015, ES2016 Packages Today
Safely Build, Publish & Maintain ES2015, ES2016 Packages TodayTorontoNodeJS
 
Avoiding callback hell with promises
Avoiding callback hell with promisesAvoiding callback hell with promises
Avoiding callback hell with promisesTorontoNodeJS
 
Building your own slack bot on the AWS stack
Building your own slack bot on the AWS stackBuilding your own slack bot on the AWS stack
Building your own slack bot on the AWS stackTorontoNodeJS
 

More from TorontoNodeJS (6)

Safely Build, Publish & Maintain ES2015, ES2016 Packages Today
Safely Build, Publish & Maintain ES2015, ES2016 Packages TodaySafely Build, Publish & Maintain ES2015, ES2016 Packages Today
Safely Build, Publish & Maintain ES2015, ES2016 Packages Today
 
nlp_compromise
nlp_compromisenlp_compromise
nlp_compromise
 
KoNote
KoNoteKoNote
KoNote
 
Avoiding callback hell with promises
Avoiding callback hell with promisesAvoiding callback hell with promises
Avoiding callback hell with promises
 
Node as an API shim
Node as an API shimNode as an API shim
Node as an API shim
 
Building your own slack bot on the AWS stack
Building your own slack bot on the AWS stackBuilding your own slack bot on the AWS stack
Building your own slack bot on the AWS stack
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Node.js API pitfalls

  • 1. Disclaimer ;-) Doesn't necessarily reflect the views of IBM, or any of my Node.js collaborators... 1
  • 2. nextTick •  [ ] in next tick of the event loop •  [ ] immediately after A returns 2 process.nextTick(function() { // Called ... });
  • 3. nextTick •  [ ] in next tick of the event loop •  [x] immediately after A returns 3 process.nextTick(function() { // Called ... });
  • 4. setImmediate •  [ ] in next tick of the event loop •  [ ] immediately after A returns 4 setImmediate(function() { // Called ... });
  • 5. setImmediate •  [x] in next tick of the event loop •  [ ] immediately after A returns 5 setImmediate(function() { // Called ... });
  • 6. nextTick vs setImmediate •  nextTick: adds callback to queue to be called immediately •  setImmediate: adds callback to queue to be called next tick 6
  • 7. worker.kill() 7 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('online', function() { this.kill('SIGHUP'); }) .on('exit', function() { console.log('Exit'); }); } else { process.on('SIGHUP', function() { console.log('Hup'); }); }
  • 8. worker.kill() •  [ ] "Hup" •  [ ] "Exit" •  [ ] "Hup" and "Exit" •  [ ] No output 8 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('online', function() { this.kill('SIGHUP'); }) .on('exit', function() { console.log('Exit'); }); } else { process.on('SIGHUP', function() { console.log('Hup'); }); }
  • 9. worker.kill() •  [ ] "Hup" •  [x] "Exit" •  [ ] "Hup" and "Exit" •  [ ] No output 9 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('online', function() { this.kill('SIGHUP'); }) .on('exit', function() { console.log('Exit'); }); } else { process.on('SIGHUP', function() { console.log('Hup'); }); }
  • 10. worker.kill() - what is it really? •  Use worker.process.kill() if you want to signal the worker •  Asymetric with worker.send(), worker.on('message', ...), etc. 10 Worker.prototype.kill = function(signo) { var proc = this.process; this.once('disconnect', function() { this.process.kill(signo || 'SIGTERM'); }); this.disconnect(); };
  • 11. worker.suicide - kill the worker •  [ ] true •  [ ] false 11 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('online', function() { this.kill('SIGTERM'); }) .on('exit', function() { // this.suicide is .... }); } else { }
  • 12. worker.suicide - kill the worker •  [x] true •  [ ] false 12 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('online', function() { this.kill('SIGTERM'); }) .on('exit', function() { // this.suicide is .... }); } else { }
  • 13. worker.suicide - exit the worker •  [ ] true •  [ ] false 13 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('exit', function() { // this.suicide is .... }); } else { process.exit(0); }
  • 14. worker.suicide - exit the worker •  [ ] true •  [x] false 14 var cluster = require('cluster'); if (cluster.isMaster) { cluster.fork() .on('exit', function() { // this.suicide is .... }); } else { process.exit(0); }
  • 15. worker.suicide - what does it mean? •  worker.disconnect() in parent (implicitly done by worker.kill()) •  process.disconnect() in worker 15 Actual meaning: "orderly exit"
  • 16. url.parse/format 16 var url = require('url'); var uri = url.parse('http://example.com:8080/path'); uri.host = 'ibm.com'; console.log(url.format(uri)); •  [ ] yes •  [ ] no Prints http://ibm.com:8080/path ...
  • 17. url.parse/format 17 var url = require('url'); var uri = url.parse('http://example.com:8080/path'); uri.host = 'ibm.com'; console.log(url.format(uri)); •  [ ] yes •  [x] no: http://ibm.com/path Prints http://ibm.com:8080/path ...
  • 18. url.parse/format •  host is "example.com:8080" •  hostname is "example.com" 18
  • 19. url.parse/format 19 var url = require('url'); var uri = url.parse('http://example.com:8080/path'); uri.hostname = 'ibm.com'; console.log(url.format(uri)); •  [ ] yes •  [ ] no Prints http://ibm.com:8080/path ...
  • 20. url.parse/format 20 var url = require('url'); var uri = url.parse('http://example.com:8080/path'); uri.hostname = 'ibm.com'; console.log(url.format(uri)); •  [ ] yes •  [x] no: http://example.com:8080/path Prints http://ibm.com:8080/path ...
  • 21. url.parse/format •  hostname and port are ignored if host is present... 21
  • 22. url.parse/format 22 var url = require('url'); var uri = url.parse('http://example.com:8080/path'); delete uri.host; uri.hostname = 'ibm.com'; console.log(url.format(uri)); •  http://ibm.com:8080/path, finally!
  • 23. url.parse/format •  parse: "http://example:8080": – port is 8080 – host is "example:8080"... why not hostport? – hostname is "example"... why not host? •  format: hostname and port are ignored if hostname is present – shouldn't they be prefered if present? 23
  • 24. path.parse/format 24 var path = require('path'); var bits = path.parse('some/dir/index.txt'); // has: .name, .ext bits.ext = '.html'; console.log(path.format(bits)); Logs some/dir/index.html... •  [ ] yes •  [ ] no
  • 25. path.parse/format 25 var path = require('path'); var bits = path.parse('some/dir/index.txt'); bits.ext = '.html'; console.log(path.format(bits)); Logs some/dir/index.html... •  [ ] yes •  [x] no: some/dir/index.txt
  • 26. path.parse/format 26 var path = require('path'); var bits = path.parse('some/dir/index.txt'); console.log(bits.base); // > index.txt delete bits.base bits.ext = '.html'; console.log(path.format(bits)); Logs some/dir/index.html... •  [ ] yes •  [ ] no Its probably like url...
  • 27. path.parse/format 27 var path = require('path'); var bits = path.parse('some/dir/index.txt'); console.log(bits.base); // > index.txt delete bits.base bits.ext = '.html'; console.log(path.format(bits)); Logs some/dir/index.html... •  [ ] yes •  [x] no: some/dir/
  • 28. path.parse/format 28 var path = require('path'); var bits = path.parse('some/dir/index.txt'); bits.base = bits.name + '.html'; console.log(path.format(bits)); // > some/dir/index.html Its just completely different, format always ignores name and ext. Correct:
  • 29. streams v1, 2, 3 29 Note that, for backwards compatibility reasons, removing 'data' event handlers will not automatically pause the stream. Also, if there are piped destinations, then calling pause() will not guarantee that the stream will remain paused once those destinations drain and ask for more data. From https://nodejs.org/api/stream.html#stream_class_stream_readable:
  • 30. streams v1, 2, 3 30 Note that, for backwards compatibility reasons, removing 'data' event handlers will not automatically pause the stream. Also, if there are piped destinations, then calling pause() will not guarantee that the stream will remain paused once those destinations drain and ask for more data. From https://nodejs.org/api/stream.html#stream_class_stream_readable: When can we delete backwards compat to v0.8?
  • 31. Question •  Laurie Voss (@seldo), NPM, Nov. 28, 2015 31 What kind of node do you want: a good one? or a (mostly) v0.8 compatible one? @octetcloud As of right now, 30.4% of registered npm accounts are less than 6 months old.
  • 32. Answer •  github, twitter, etc.. •  Be tolerant (or intolerant) of breakages, but what you say will effect what happens. 32 Its yours (and a lot of other people's) Node.js, speak out:
  • 33. Flames to: •  github: @sam-github •  email: rsam@ca.ibm.com •  twitter: @octetcloud •  talk source: https://gist.github.com/sam-github/4c5c019b92cf95fb6571, or https://goo.gl/2RWpqE 33