SlideShare a Scribd company logo
1 of 16
Download to read offline
Your devices deserve more than your files
v
Setup 
<script src="pouchdb.min.js"></script> 
$ npm install pouchdb ­­save 
var pouchdb = require('pouchdb');
Synchronization 
var db = new PouchDB('todos'); 
var remoteCouch = 'https://mycouch/todos'; 
var opts = {live: true}; 
db.sync(remoteCouch, opts) 
.on('change', onChange) 
.on('uptodate', onUpdate) 
.on('error', onError);
Conflicts 
var opts = {conflicts: true}; 
db.get('docid', opts, function (err, doc) { 
var rev = doc._rev; 
var conflictRev = doc._conflicts[0]; 
rev = selectRevision(rev, conflictRev); 
opts = {rev: rev}; 
db.get('docid', opts, function (err, doc) { 
db.put(doc); 
}); 
};
Messaging (pub/sub) 
function onChange (change) { 
if(change.doc.type === 'message' 
&& change.doc.chan === 'mychan') { 
console.log(doc.content); 
db.put({ 
type: 'message', 
content: 'Got it! Now I publish' 
}); 
}
pouchdb.com 
pouchdb/pouchdb 
pouchdb/pouchdb-server 
colinskow/pouch-mirror 
natevw/PeerPouch 
cozy-labs/[mobile|desktop]
Device Synchronization with Javascript and PouchDB

More Related Content

What's hot

What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then some
Ohad Kravchick
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
Social Analytics with MongoDB
Social Analytics with MongoDBSocial Analytics with MongoDB
Social Analytics with MongoDB
Patrick Stokes
 

What's hot (20)

Putting the Go in MongoDB: How We Rebuilt The MongoDB Tools in Go
Putting the Go in MongoDB: How We Rebuilt The MongoDB Tools in GoPutting the Go in MongoDB: How We Rebuilt The MongoDB Tools in Go
Putting the Go in MongoDB: How We Rebuilt The MongoDB Tools in Go
 
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionGCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow Introduction
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Lite
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then some
 
Event Pipe - Lambda Architecture
Event Pipe - Lambda ArchitectureEvent Pipe - Lambda Architecture
Event Pipe - Lambda Architecture
 
Intro To Couch Db
Intro To Couch DbIntro To Couch Db
Intro To Couch Db
 
Building Scalable Websites with Perl
Building Scalable Websites with PerlBuilding Scalable Websites with Perl
Building Scalable Websites with Perl
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbitBackground Tasks in Node - Evan Tahler, TaskRabbit
Background Tasks in Node - Evan Tahler, TaskRabbit
 
Automating Workflows for Analytics Pipelines
Automating Workflows for Analytics PipelinesAutomating Workflows for Analytics Pipelines
Automating Workflows for Analytics Pipelines
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Client Side Storage
Client Side StorageClient Side Storage
Client Side Storage
 
Analyse Yourself
Analyse YourselfAnalyse Yourself
Analyse Yourself
 
Common Pitfalls for your Drupal Site, and How to Avoid Them
Common Pitfalls for your Drupal Site, and How to Avoid ThemCommon Pitfalls for your Drupal Site, and How to Avoid Them
Common Pitfalls for your Drupal Site, and How to Avoid Them
 
Dmp hadoop getting_start
Dmp hadoop getting_startDmp hadoop getting_start
Dmp hadoop getting_start
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
Docker Monitoring Webinar
Docker Monitoring  WebinarDocker Monitoring  Webinar
Docker Monitoring Webinar
 
Getting started with node JS
Getting started with node JSGetting started with node JS
Getting started with node JS
 
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
 
Social Analytics with MongoDB
Social Analytics with MongoDBSocial Analytics with MongoDB
Social Analytics with MongoDB
 

Viewers also liked

Couch DB/PouchDB approach for hybrid mobile applications
Couch DB/PouchDB approach for hybrid mobile applicationsCouch DB/PouchDB approach for hybrid mobile applications
Couch DB/PouchDB approach for hybrid mobile applications
Ihor Malytskyi
 
วารุณี
วารุณีวารุณี
วารุณี
warunee18
 
Sherry power point 3
Sherry power point 3Sherry power point 3
Sherry power point 3
Sherry14
 
Leverage social media to drive business the case sept 2012
Leverage social media to drive business the case sept 2012Leverage social media to drive business the case sept 2012
Leverage social media to drive business the case sept 2012
SimoneVersteeg
 
IEC Orientation first year for B-Tech
IEC Orientation first year for B-TechIEC Orientation first year for B-Tech
IEC Orientation first year for B-Tech
iec
 
Volcanestaller
VolcanestallerVolcanestaller
Volcanestaller
Imacp
 
Weekly news (4th oct – 9th oct
Weekly news (4th oct – 9th octWeekly news (4th oct – 9th oct
Weekly news (4th oct – 9th oct
Nitin Kochhar
 
[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...
[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...
[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...
Plan Politika
 
Velazquez
VelazquezVelazquez
Velazquez
J Luque
 

Viewers also liked (20)

Offline-First Apps with PouchDB
Offline-First Apps with PouchDB Offline-First Apps with PouchDB
Offline-First Apps with PouchDB
 
Easy offline-first mobile and desktop web apps with PouchDB
Easy offline-first mobile and desktop web apps with PouchDBEasy offline-first mobile and desktop web apps with PouchDB
Easy offline-first mobile and desktop web apps with PouchDB
 
Couch DB/PouchDB approach for hybrid mobile applications
Couch DB/PouchDB approach for hybrid mobile applicationsCouch DB/PouchDB approach for hybrid mobile applications
Couch DB/PouchDB approach for hybrid mobile applications
 
Apache CouchDB
Apache CouchDBApache CouchDB
Apache CouchDB
 
Offline first, the painless way
Offline first, the painless wayOffline first, the painless way
Offline first, the painless way
 
Idris: Chocolatey Yumm-Tastic
Idris: Chocolatey Yumm-TasticIdris: Chocolatey Yumm-Tastic
Idris: Chocolatey Yumm-Tastic
 
วารุณี
วารุณีวารุณี
วารุณี
 
Sherry power point 3
Sherry power point 3Sherry power point 3
Sherry power point 3
 
2 weekly news
2 weekly news2 weekly news
2 weekly news
 
Leverage social media to drive business the case sept 2012
Leverage social media to drive business the case sept 2012Leverage social media to drive business the case sept 2012
Leverage social media to drive business the case sept 2012
 
IEC Orientation first year for B-Tech
IEC Orientation first year for B-TechIEC Orientation first year for B-Tech
IEC Orientation first year for B-Tech
 
Volcanestaller
VolcanestallerVolcanestaller
Volcanestaller
 
Weekly news (4th oct – 9th oct
Weekly news (4th oct – 9th octWeekly news (4th oct – 9th oct
Weekly news (4th oct – 9th oct
 
SJob
SJobSJob
SJob
 
[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...
[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...
[plan politika] Indonesian Youth and Politics : Serial Slide Bakal Calon Gube...
 
Bee module 1
Bee module 1Bee module 1
Bee module 1
 
Cactus explorer 14 complete
Cactus explorer 14 completeCactus explorer 14 complete
Cactus explorer 14 complete
 
Got Community?
Got Community?Got Community?
Got Community?
 
Weekly news (3)
Weekly news (3)Weekly news (3)
Weekly news (3)
 
Velazquez
VelazquezVelazquez
Velazquez
 

Similar to Device Synchronization with Javascript and PouchDB

Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
Carlos Sanchez
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 

Similar to Device Synchronization with Javascript and PouchDB (20)

Synchronisation de périphériques avec Javascript et PouchDB
Synchronisation de périphériques avec Javascript et PouchDBSynchronisation de périphériques avec Javascript et PouchDB
Synchronisation de périphériques avec Javascript et PouchDB
 
Hadoop
HadoopHadoop
Hadoop
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
EWD 3 Training Course Part 20: The DocumentNode Object
EWD 3 Training Course Part 20: The DocumentNode ObjectEWD 3 Training Course Part 20: The DocumentNode Object
EWD 3 Training Course Part 20: The DocumentNode Object
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Fatc
FatcFatc
Fatc
 
8. Move in Laravel
8. Move in Laravel8. Move in Laravel
8. Move in Laravel
 
Cakephp2study tips集
Cakephp2study tips集Cakephp2study tips集
Cakephp2study tips集
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Angular js security
Angular js securityAngular js security
Angular js security
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
6. Add numbers in Laravel
6. Add numbers in Laravel6. Add numbers in Laravel
6. Add numbers in Laravel
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 

More from Frank Rousseau

20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 

More from Frank Rousseau (17)

Node.js et NPM: de la récupération de dépendances à la publication de paquets
Node.js et NPM: de la récupération de dépendances à la publication de paquetsNode.js et NPM: de la récupération de dépendances à la publication de paquets
Node.js et NPM: de la récupération de dépendances à la publication de paquets
 
Newebe, un Réseau Social ou Chacun est Indépendant
Newebe, un Réseau Social ou Chacun est IndépendantNewebe, un Réseau Social ou Chacun est Indépendant
Newebe, un Réseau Social ou Chacun est Indépendant
 
Conseils sur le Design pour les Développeurs par un Développeur
Conseils sur le Design pour les Développeurs par un DéveloppeurConseils sur le Design pour les Développeurs par un Développeur
Conseils sur le Design pour les Développeurs par un Développeur
 
Développement web sans souffrance avec Cozy
Développement web sans souffrance avec CozyDéveloppement web sans souffrance avec Cozy
Développement web sans souffrance avec Cozy
 
Cozy, a Personal PaaS
Cozy, a Personal PaaSCozy, a Personal PaaS
Cozy, a Personal PaaS
 
Newebe, a social network where all users are independent
Newebe, a social network where all users are independentNewebe, a social network where all users are independent
Newebe, a social network where all users are independent
 
Cozy Cloud, Pour un meilleur web
Cozy Cloud, Pour un meilleur webCozy Cloud, Pour un meilleur web
Cozy Cloud, Pour un meilleur web
 
Comment les grands acteurs du web s'improvisent magiciens et jouent avec nos ...
Comment les grands acteurs du web s'improvisent magiciens et jouent avec nos ...Comment les grands acteurs du web s'improvisent magiciens et jouent avec nos ...
Comment les grands acteurs du web s'improvisent magiciens et jouent avec nos ...
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
A startup with no office, hipster tools and open source products
A startup with no office, hipster tools and open source productsA startup with no office, hipster tools and open source products
A startup with no office, hipster tools and open source products
 
How to make a Personal Single Page Application with Cozy
How to make a Personal Single Page Application with CozyHow to make a Personal Single Page Application with Cozy
How to make a Personal Single Page Application with Cozy
 
How to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJSHow to quickly make REST APIs with CompoundJS
How to quickly make REST APIs with CompoundJS
 
Haibu: dev deployment is fast and easy again
Haibu: dev deployment is fast and easy againHaibu: dev deployment is fast and easy again
Haibu: dev deployment is fast and easy again
 
Cozy Cloud, JDLL 2012
Cozy Cloud, JDLL 2012Cozy Cloud, JDLL 2012
Cozy Cloud, JDLL 2012
 
Newebe, JDLL 2012
Newebe, JDLL 2012Newebe, JDLL 2012
Newebe, JDLL 2012
 
Newebe for RMLL 2012
Newebe for RMLL 2012Newebe for RMLL 2012
Newebe for RMLL 2012
 
Cozy Cloud for RMLL 2012
Cozy Cloud for RMLL 2012Cozy Cloud for RMLL 2012
Cozy Cloud for RMLL 2012
 

Recently uploaded

Recently uploaded (20)

Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 

Device Synchronization with Javascript and PouchDB

  • 1. Your devices deserve more than your files
  • 2.
  • 3. v
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Setup <script src="pouchdb.min.js"></script> $ npm install pouchdb ­­save var pouchdb = require('pouchdb');
  • 12. Synchronization var db = new PouchDB('todos'); var remoteCouch = 'https://mycouch/todos'; var opts = {live: true}; db.sync(remoteCouch, opts) .on('change', onChange) .on('uptodate', onUpdate) .on('error', onError);
  • 13. Conflicts var opts = {conflicts: true}; db.get('docid', opts, function (err, doc) { var rev = doc._rev; var conflictRev = doc._conflicts[0]; rev = selectRevision(rev, conflictRev); opts = {rev: rev}; db.get('docid', opts, function (err, doc) { db.put(doc); }); };
  • 14. Messaging (pub/sub) function onChange (change) { if(change.doc.type === 'message' && change.doc.chan === 'mychan') { console.log(doc.content); db.put({ type: 'message', content: 'Got it! Now I publish' }); }
  • 15. pouchdb.com pouchdb/pouchdb pouchdb/pouchdb-server colinskow/pouch-mirror natevw/PeerPouch cozy-labs/[mobile|desktop]