SlideShare a Scribd company logo
1 of 35
Download to read offline
What the web platform can learn from Node.js
and what your web frontend can learn too!
Will Binns-Smith • Frontend Developer, Bitbucket • Atlassian • @wbinnssmith
var request = new XMLHttpRequest();
request.addEventListener("load", function () {
console.log(JSON.parse(this.responseText));
});
request.addEventListener("error", function (e) {
console.error("oh noes!!");
});
request.open("POST", "http://www.example.org/endpoint");
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json");
request.send(JSON.stringify({
my: 'data'
}));
POST { my: ‘data’ }
to http://example.com/endpoint
$.ajax({
method: "POST",
url: "http://example.com/endpoint",
data: JSON.stringify({
my: "data"
}),
contentType: "application/json",
dataType: "json",
success: () => {
console.log(JSON.parse(this.responseText));
},
failure: () => {
console.error("oh noes!!");
}
});
$.ajax({
method: "POST",
url: "http://example.com/endpoint",
data: JSON.stringify({
my: "data"
}),
contentType: "application/json",
dataType: "json"
}).done(() => {
console.log(JSON.parse(this.responseText));
}).fail(() => {
console.error("oh noes!!");
});
$.postJSON
POST { my: ‘data’ }
to http://example.com/endpoint
var request = require(‘request’);
request.post('http://localhost:3000/endpoint', {
json: true,
body: { foo: 'bar' }
}, (err, resp) => {
if (err) throw Error(err);
console.log(resp);
});
too bad we can’t change XHR
without breaking the internet
this happens a lot
DOM Mutation Events -> DOM Mutation Observers
Object.observe() -> Proxies, setters
AppCache -> ServiceWorkers
showModalDialog() -> <dialog>, Web Components
a lot of this is preventable.
we need a way to make mistakes and
improve upon them
solution:
focused modules. from userland.
(and lots of them)
array-union
array-uniq
camelcase
object-assign
is-blob
… and 761 others on npm
sindresorhus
negative-zero
'use strict';
module.exports = function (x) {
return x === 0 && 1 / x === -Infinity;
};
sindresorhus
it says what it does, not how to do it
(which in JavaScript often makes no sense anyway)
why?
var isNegativeZero = require(‘negative-zero’);
isNegativeZero(5); // false
isNegativeZero(-0); // true
isNegativeZero(0); // false
sindresorhus
we need tooling for lots and
lots of modules. just like we
have in Node
so let’s bring npm to the browser
+
one script tag. (nearly) all of npm.
npm install the-future
Object.assign -> require(‘object-assign’)
Promise -> require(‘native-promise-only’)
Map -> require(‘es6-map’)
-> require(‘babel-core’)
require(‘core-js’)
npm install emojilib
{
"100": "💯",
"1234": "🔢",
"grinning": "😀",
"grin": "😁",
"joy": "😂",
"smiley": "😃",
"smile": "😄",
"sweat_smile": "😅",
"laughing": "😆",
npm install baboon-image-url
module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAA
don’t like a module’s API? just
npm install a different one
single responsibilities make
switching easy
write a module with a terrible
API? just fix it and bump the
major version
nobody’s apps break
it’s fearless iteration for your
app and your modules
more than
1,000modules in Bitbucket Cloud’s
frontend JavaScript alone.
the extensible web manifesto
low-level APIs from the browsers,
high-level abstractions from
developers
so why can’t I have request’s
API in the browser?
of course you can!
take your pick.
xhr
superagent*
axios*
hyperquest*
nets*
BUT!
the web has fetch now!
fetch(‘http://example.com/endpoint', {
method: ‘post’,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
my: 'data',
})
}).then(response => {
return response.json();
}).then(reponse => {
console.log(response);
});
fetch appears high-level and convenient
but also comes with Request, Response,
and WHATWG streams. let’s use these to
build more things!
extend the web forward
one tiny, tiny piece at a time.
npm install thanks --save
Will Binns-Smith • Frontend Developer, Bitbucket • Atlassian • @wbinnssmith

More Related Content

What's hot

HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
Frédéric Harper
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
Jeongkyu Shin
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileFirefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Robert Nyman
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
D
 
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, CroatiaLeave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Robert Nyman
 

What's hot (20)

Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"
 
Persistent mobile JavaScript
Persistent mobile JavaScriptPersistent mobile JavaScript
Persistent mobile JavaScript
 
Puppet at janrain
Puppet at janrainPuppet at janrain
Puppet at janrain
 
Rubyslava + PyVo #48
Rubyslava + PyVo #48Rubyslava + PyVo #48
Rubyslava + PyVo #48
 
Node.js Spplication Scaling
Node.js Spplication ScalingNode.js Spplication Scaling
Node.js Spplication Scaling
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
 
Ufo Ship for AWS ECS
Ufo Ship for AWS ECSUfo Ship for AWS ECS
Ufo Ship for AWS ECS
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
ニコニコ動画を検索可能にしてみよう
ニコニコ動画を検索可能にしてみようニコニコ動画を検索可能にしてみよう
ニコニコ動画を検索可能にしてみよう
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
연구자 및 교육자를 위한 계산 및 분석 플랫폼 설계 - PyCon KR 2015
 
What is nodejs
What is nodejsWhat is nodejs
What is nodejs
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileFirefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobile
 
"今" 使えるJavaScriptのトレンド
"今" 使えるJavaScriptのトレンド"今" 使えるJavaScriptのトレンド
"今" 使えるJavaScriptのトレンド
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
ReactJS & Material-ui Hello world
ReactJS & Material-ui Hello worldReactJS & Material-ui Hello world
ReactJS & Material-ui Hello world
 
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, CroatiaLeave No One Behind with HTML5 - FFWD.PRO, Croatia
Leave No One Behind with HTML5 - FFWD.PRO, Croatia
 

Similar to What the web platform (and your app!) can learn from Node.js

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 

Similar to What the web platform (and your app!) can learn from Node.js (20)

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
Node.js
Node.jsNode.js
Node.js
 
Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal core
 
Mozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSMozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJS
 
Progressive What Apps?
Progressive What Apps?Progressive What Apps?
Progressive What Apps?
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQL
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming En
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
mobl
moblmobl
mobl
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
huhu
huhuhuhu
huhu
 
Micro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMicro app-framework - NodeLive Boston
Micro app-framework - NodeLive Boston
 
Micro app-framework
Micro app-frameworkMicro app-framework
Micro app-framework
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

What the web platform (and your app!) can learn from Node.js

  • 1. What the web platform can learn from Node.js and what your web frontend can learn too! Will Binns-Smith • Frontend Developer, Bitbucket • Atlassian • @wbinnssmith
  • 2. var request = new XMLHttpRequest(); request.addEventListener("load", function () { console.log(JSON.parse(this.responseText)); }); request.addEventListener("error", function (e) { console.error("oh noes!!"); }); request.open("POST", "http://www.example.org/endpoint"); request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Content-Type", "application/json"); request.send(JSON.stringify({ my: 'data' }));
  • 3. POST { my: ‘data’ } to http://example.com/endpoint
  • 4. $.ajax({ method: "POST", url: "http://example.com/endpoint", data: JSON.stringify({ my: "data" }), contentType: "application/json", dataType: "json", success: () => { console.log(JSON.parse(this.responseText)); }, failure: () => { console.error("oh noes!!"); } });
  • 5. $.ajax({ method: "POST", url: "http://example.com/endpoint", data: JSON.stringify({ my: "data" }), contentType: "application/json", dataType: "json" }).done(() => { console.log(JSON.parse(this.responseText)); }).fail(() => { console.error("oh noes!!"); }); $.postJSON
  • 6.
  • 7. POST { my: ‘data’ } to http://example.com/endpoint
  • 8. var request = require(‘request’); request.post('http://localhost:3000/endpoint', { json: true, body: { foo: 'bar' } }, (err, resp) => { if (err) throw Error(err); console.log(resp); });
  • 9.
  • 10. too bad we can’t change XHR without breaking the internet
  • 11. this happens a lot DOM Mutation Events -> DOM Mutation Observers Object.observe() -> Proxies, setters AppCache -> ServiceWorkers showModalDialog() -> <dialog>, Web Components a lot of this is preventable.
  • 12. we need a way to make mistakes and improve upon them
  • 13. solution: focused modules. from userland. (and lots of them)
  • 15. negative-zero 'use strict'; module.exports = function (x) { return x === 0 && 1 / x === -Infinity; }; sindresorhus
  • 16. it says what it does, not how to do it (which in JavaScript often makes no sense anyway) why? var isNegativeZero = require(‘negative-zero’); isNegativeZero(5); // false isNegativeZero(-0); // true isNegativeZero(0); // false
  • 18. we need tooling for lots and lots of modules. just like we have in Node
  • 19. so let’s bring npm to the browser +
  • 20. one script tag. (nearly) all of npm.
  • 21. npm install the-future Object.assign -> require(‘object-assign’) Promise -> require(‘native-promise-only’) Map -> require(‘es6-map’) -> require(‘babel-core’) require(‘core-js’)
  • 22. npm install emojilib { "100": "💯", "1234": "🔢", "grinning": "😀", "grin": "😁", "joy": "😂", "smiley": "😃", "smile": "😄", "sweat_smile": "😅", "laughing": "😆",
  • 23. npm install baboon-image-url module.exports = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAA
  • 24. don’t like a module’s API? just npm install a different one single responsibilities make switching easy
  • 25. write a module with a terrible API? just fix it and bump the major version nobody’s apps break
  • 26. it’s fearless iteration for your app and your modules
  • 27. more than 1,000modules in Bitbucket Cloud’s frontend JavaScript alone.
  • 28. the extensible web manifesto low-level APIs from the browsers, high-level abstractions from developers
  • 29. so why can’t I have request’s API in the browser?
  • 30. of course you can! take your pick. xhr superagent* axios* hyperquest* nets*
  • 31. BUT! the web has fetch now!
  • 32. fetch(‘http://example.com/endpoint', { method: ‘post’, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ my: 'data', }) }).then(response => { return response.json(); }).then(reponse => { console.log(response); });
  • 33. fetch appears high-level and convenient but also comes with Request, Response, and WHATWG streams. let’s use these to build more things!
  • 34. extend the web forward one tiny, tiny piece at a time.
  • 35. npm install thanks --save Will Binns-Smith • Frontend Developer, Bitbucket • Atlassian • @wbinnssmith