SlideShare una empresa de Scribd logo
1 de 45
©2015 Couchbase Inc. 1
Nic Raboy, Developer Advocate at Couchbase
Quick and Easy Development with Node.js
and Couchbase Server
©2015 Couchbase Inc. 2
About Me
Nic Raboy
Developer Advocate at Couchbase
@nraboy (Twitter)
Node.js, Android, Java, Ionic Framework, NoSQL, SQL
©2015 Couchbase Inc. 3
What Is Couchbase?
©2015 Couchbase Inc. 4
What makes Couchbase unique?
4
Performance &
scalability leader
Sub millisecond latency
with high throughput;
memory-centric
architecture
Multi-
purpose
Simplified
administration
Easy to deploy &
manage; integrated
Admin Console, single-
click cluster expansion
& rebalance
Cache, key value store,
document database,
and local/mobile
database in single
platform
Always-on
availability
Data replication across
nodes, clusters, and
data centers
Enterprises choose Couchbase for several key advantages
24x365
©2015 Couchbase Inc. 5
 Consolidated cache and
database
 Tune memory required based
on application requirements
Multi-purpose database supports many uses
5
5
Tunable built-in
cache
Flexible schemas
with JSON
Couchbase Lite
 Represent data with varying
schemas using JSON on the
server or on the device
 Index and query data with
Javascript views
 Light weight embedded DB for
always available apps
 Sync Gateway syncs data
seamlessly with Couchbase
Server
©2015 Couchbase Inc. 6
Couchbase leads in performance and scalability
Auto
Sharding
Memory-memory
XDCR
Single
NodeType
 No manual sharding
 Database manages data
movement to scale out – not
the user
 Market’s only memory-to-
memory database replication
across clusters and geos
 Provides disaster recover /
data locality
 Hugely simplifies management
of clusters
 Easy to scale clusters by adding
any number of nodes
©2015 Couchbase Inc. 7
Available Couchbase Server SDKs
And more…
©2015 Couchbase Inc. 8
Overview of the Node.js SDK
©2015 Couchbase Inc. 9
Node.js SDK
 Uses the high performance Couchbase C library
 Compatible with Node.js frameworks
 Minimal coding
©2015 Couchbase Inc. 10
Node.js
// InstantiateThe Query API
var couchbase = require(“couchbase”);
var myCluster = new Couchbase.Cluster(“localhost:8091”);
var myBucket = myCluster.openBucket(“travel-sample”);
var myQuery = couchbase.N1qlQuery();
©2015 Couchbase Inc. 11
Node.js
function query(sql, done) {
var queryToRun = myQuery.fromString(sql);
myBucket.query(queryToRun, function(error, result) {
if(error) {
console.log(“ERROR: “, error);
done(error, null);
return;
}
done(null, result);
return;
});
}
©2015 Couchbase Inc. 12
Node.js
function query(sql, done) {
var queryToRun = myQuery.fromString(sql);
myBucket.query(queryToRun, function(error, result) {
if(error) {
console.log(“ERROR: “, error);
done(error, null);
return;
}
done(null, result);
return;
});
}
©2015 Couchbase Inc. 13
Node.js
function query(sql, done) {
var queryToRun = myQuery.fromString(sql);
myBucket.query(queryToRun, function(error, result) {
if(error) {
console.log(“ERROR: “, error);
done(error, null);
return;
}
done(null, result);
return;
});
}
©2015 Couchbase Inc. 14
Node.js
function query(sql, done) {
var queryToRun = myQuery.fromString(sql);
myBucket.query(queryToRun, function(error, result) {
if(error) {
console.log(“ERROR: “, error);
done(error, null);
return;
}
done(null, result);
return;
});
}
©2015 Couchbase Inc. 15
Node.js
function query(sql, done) {
var queryToRun = myQuery.fromString(sql);
myBucket.query(queryToRun, function(error, result) {
if(error) {
console.log(“ERROR: “, error);
done(error, null);
return;
}
done(null, result);
return;
});
}
©2015 Couchbase Inc. 16
Node.js
function query(sql, done) {
var queryToRun = myQuery.fromString(sql);
myBucket.query(queryToRun, function(error, result) {
if(error) {
console.log(“ERROR: “, error);
done(error, null);
return;
}
done(null, result);
return;
});
}
©2015 Couchbase Inc. 17
Node.js Data Querying
 Document lookups
 Couchbase views
 N1QL
©2015 Couchbase Inc. 18
Node.jsView Query
var query =ViewQuery.from("travel", "by_name").skip(6).limit(3);
myBucket.query(query, function(error, results) {
for(i in results) {
console.log("Row: ", results[i]);
}
});
DemoTime!
©2015 Couchbase Inc. 20
Node.js Application Design
AngularJS
Client Frontend
Node.js
Server Backend
©2015 Couchbase Inc. 21
Node.js Separation of Frontend and Backend
 No Jade markup
 API driven
 Less client and server coupling
 The backend can evolve without affecting the frontend
 Frontend can be extended to web as well as mobile
©2015 Couchbase Inc. 22
Multiple Frontends & One Backend
©2015 Couchbase Inc. 23
The Node.js Backend
©2015 Couchbase Inc. 24
Node.js Configuration
// config.json
{
"couchbase": {
"server": "127.0.0.1:8091",
"bucket": "restful-sample"
}
}
©2015 Couchbase Inc. 25
Node.js Configuration
// Project’s app.js file
var express = require("express");
var bodyParser = require("body-parser");
var couchbase = require("couchbase");
var path = require("path");
var config = require("./config");
var app = express();
©2015 Couchbase Inc. 26
Node.js Configuration
// app.js continued…
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
module.exports.bucket = (new
couchbase.Cluster(config.couchbase.server)).openBucket(config.couchbase.bucket);
app.use(express.static(path.join(__dirname, "public")));
var routes = require("./routes/routes.js")(app);
var server = app.listen(3000, function () {
console.log("Listening on port %s...", server.address().port);
});
©2015 Couchbase Inc. 27
Node.js Create or Update Endpoint
// routes.js
app.post("/api/create", function(req, res) {
if(!req.body.firstname) {
return res.status(400).send({"status": "error", "message": "A firstname is required"});
}
// …
RecordModel.create(req.body, function(error, result) {
if(error) {
return res.status(400).send(error);
}
res.send(result);
});
});
©2015 Couchbase Inc. 28
Node.js Get Document Endpoint
// routes.js continued…
app.get("/api/get", function(req, res) {
if(!req.query.document_id) {
return res.status(400).send({"status": "error", "message": "A document id is required"});
}
RecordModel.getByDocumentId(req.query.document_id, function(error, result) {
if(error) {
return res.status(400).send(error);
}
res.send(result);
});
});
©2015 Couchbase Inc. 29
Node.js Delete Endpoint
// routes.js continued…
app.post("/api/delete", function(req, res) {
if(!req.body.document_id) {
return res.status(400).send({"status": "error", "message": "A document id is required"});
}
RecordModel.delete(req.body.document_id, function(error, result) {
if(error) {
return res.status(400).send(error);
}
res.send(result);
});
});
©2015 Couchbase Inc. 30
Node.js Upsert Document Function
// recordmodel.js
RecordModel.save = function(data, callback) {
var jsonObject = {
type: “user”,
firstname: data.firstname,
lastname: data.lastname,
email: data.email
}
var documentId = data.document_id ? data.document_id : uuid.v4();
db.upsert(documentId, jsonObject, function(error, result) {
if(error) {
return callback(error, null);
}
callback(null, {message: "success", data: result});
});
}
©2015 Couchbase Inc. 31
Couchbase JSON Document
©2015 Couchbase Inc. 32
Node.js Get Document with N1QL Function
// recordmodel.js continued…
RecordModel.getByDocumentId = function(documentId, callback) {
var statement = "SELECT firstname, lastname, email " +
"FROM `" + config.couchbase.bucket + "` AS users " +
"WHERE META(users).id = $1";
var query = N1qlQuery.fromString(statement);
db.query(query, [documentId], function(error, result) {
if(error) {
return callback(error, null);
}
callback(null, result);
});
};
©2015 Couchbase Inc. 33
Node.js Delete Document Function
// recordmodel.js continued…
RecordModel.delete = function(documentId, callback) {
db.remove(documentId, function(error, result) {
if(error) {
callback(error, null);
return;
}
callback(null, {message: "success", data: result});
});
};
©2015 Couchbase Inc. 34
The AngularJS Frontend
©2015 Couchbase Inc. 35
// AngularJS app.js
$scope.fetchAll = function() {
$http(
{
method: "GET",
url: "/api/getAll"
}
)
.success(function(result) {
for(var i = 0; i < result.length; i++) {
$scope.items[result[i].id] = result[i];
}
});
}
©2015 Couchbase Inc. 36
// AngularJS app.s
$scope.save = function(firstname, lastname, email) {
$http(
{
method: "POST",
url: "/api/create",
data: {
firstname: firstname,
lastname: lastname,
email: email,
document_id: $stateParams.documentId
}
}
)
}
A Further Look AtThe Code…
©2015 Couchbase Inc. 38
More Complex Node.js Queries
©2015 Couchbase Inc. 39
Node.jsTravel Sample
FlightPath.findAll = function(documentId, callback) {
var statement = "SELECT faa AS fromAirport, geo " +
"FROM `" + config.couchbase.bucket + "` r" +
"WHERE airportname = $1 " +
"UNION SELECT faa AS toAirport, geo " +
"FROM `" + config.couchbase.bucket + "` r" +
"WHERE airportname = $2";
var query = N1qlQuery.fromString(statement);
db.query(query, [from, to], function(error, result) {
if(error) {
return callback(error, null);
}
callback(null, result);
});
};
©2015 Couchbase Inc. 40
Node.jsTravel Sample
FlightPath.findAll = function(documentId, callback) {
var statement = "SELECT r.id, a.name, s.flight, s.utc, r.sourceairport, r.destinationairport, r.equipment " +
"FROM `" + config.couchbase.bucket + "` r" +
"UNNEST r.schedule s " +
"JOIN `" + config.couchbase.bucket + "` a ON KEYS r.airlineid " +
"WHERE r.sourceairport = $1AND r.destinationairport = $2AND s.day = $3 ”
"ORDER BY a.name";
var query = N1qlQuery.fromString(statement);
db.query(query, [queryFrom, queryTo, leave], function(error, result) {
if(error) {
return callback(error, null);
}
callback(null, result);
});
};
©2015 Couchbase Inc. 41
Node.js Sample Applications
https://github.com/couchbaselabs/try-cb-nodejs
https://github.com/couchbaselabs/restful-angularjs-nodejs
©2015 Couchbase Inc. 42
Couchbase N1QLTutorial
http://query.pub.couchbase.com/tutorial
Questions?
©2014 Couchbase, Inc.
©2015 Couchbase Inc. 44
Couchbase
We’re Hiring!
©2014 Couchbase, Inc.
©2015 Couchbase Inc. 45©2014 Couchbase, Inc.
ThankYou
Nic Raboy
Developer Advocate at Couchbase
@nraboy (Twitter)

Más contenido relacionado

La actualidad más candente

Google App Engine/ Java Application Development
Google App Engine/ Java Application DevelopmentGoogle App Engine/ Java Application Development
Google App Engine/ Java Application DevelopmentShuji Watanabe
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...Sencha
 
Azure and web sites hackaton deck
Azure and web sites hackaton deckAzure and web sites hackaton deck
Azure and web sites hackaton deckAlexey Bokov
 
Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史Simon Su
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsAtlassian
 
Akka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in PracticeAkka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in PracticeRoland Kuhn
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance DrupalJeff Geerling
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSGunnar Hillert
 
Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018DocFluix, LLC
 
Cloud Foundry Deployment Tools: BOSH vs Juju Charms
Cloud Foundry Deployment Tools:  BOSH vs Juju CharmsCloud Foundry Deployment Tools:  BOSH vs Juju Charms
Cloud Foundry Deployment Tools: BOSH vs Juju CharmsAltoros
 
Architectural changes in the repo in 6.1 and beyond
Architectural changes in the repo in 6.1 and beyondArchitectural changes in the repo in 6.1 and beyond
Architectural changes in the repo in 6.1 and beyondStefan Kopf
 
Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?Izzet Mustafaiev
 
Deploying and running Grails in the cloud
Deploying and running Grails in the cloudDeploying and running Grails in the cloud
Deploying and running Grails in the cloudPhilip Stehlik
 
GigaSpaces Cloudify - The PaaS Jailbreaker
GigaSpaces Cloudify - The PaaS Jailbreaker GigaSpaces Cloudify - The PaaS Jailbreaker
GigaSpaces Cloudify - The PaaS Jailbreaker Uri Cohen
 
Ansible for large scale deployment
Ansible for large scale deploymentAnsible for large scale deployment
Ansible for large scale deploymentKarthik .P.R
 
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
Creating Real-Time Data Mashups with Node.JS and Adobe CQCreating Real-Time Data Mashups with Node.JS and Adobe CQ
Creating Real-Time Data Mashups with Node.JS and Adobe CQiCiDIGITAL
 
Sql source control
Sql source controlSql source control
Sql source controlAndyPickett
 

La actualidad más candente (20)

Google App Engine/ Java Application Development
Google App Engine/ Java Application DevelopmentGoogle App Engine/ Java Application Development
Google App Engine/ Java Application Development
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
 
Azure and web sites hackaton deck
Azure and web sites hackaton deckAzure and web sites hackaton deck
Azure and web sites hackaton deck
 
Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian Plugins
 
Akka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in PracticeAkka and AngularJS – Reactive Applications in Practice
Akka and AngularJS – Reactive Applications in Practice
 
Lspe
LspeLspe
Lspe
 
Azkaban
AzkabanAzkaban
Azkaban
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018Developing Azure Functions for Flow and Nintex SPS SD 2018
Developing Azure Functions for Flow and Nintex SPS SD 2018
 
Cloud Foundry Deployment Tools: BOSH vs Juju Charms
Cloud Foundry Deployment Tools:  BOSH vs Juju CharmsCloud Foundry Deployment Tools:  BOSH vs Juju Charms
Cloud Foundry Deployment Tools: BOSH vs Juju Charms
 
Architectural changes in the repo in 6.1 and beyond
Architectural changes in the repo in 6.1 and beyondArchitectural changes in the repo in 6.1 and beyond
Architectural changes in the repo in 6.1 and beyond
 
Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?Docker. Does it matter for Java developer ?
Docker. Does it matter for Java developer ?
 
Deploying and running Grails in the cloud
Deploying and running Grails in the cloudDeploying and running Grails in the cloud
Deploying and running Grails in the cloud
 
GigaSpaces Cloudify - The PaaS Jailbreaker
GigaSpaces Cloudify - The PaaS Jailbreaker GigaSpaces Cloudify - The PaaS Jailbreaker
GigaSpaces Cloudify - The PaaS Jailbreaker
 
Iac d.damyanov 4.pptx
Iac d.damyanov 4.pptxIac d.damyanov 4.pptx
Iac d.damyanov 4.pptx
 
Ansible for large scale deployment
Ansible for large scale deploymentAnsible for large scale deployment
Ansible for large scale deployment
 
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
Creating Real-Time Data Mashups with Node.JS and Adobe CQCreating Real-Time Data Mashups with Node.JS and Adobe CQ
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
 
Sql source control
Sql source controlSql source control
Sql source control
 

Destacado

Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Red Hat Developers
 
Syllabus B.Pharm 2008-09
Syllabus B.Pharm 2008-09Syllabus B.Pharm 2008-09
Syllabus B.Pharm 2008-09Imran Nur Manik
 
Sldo.Guaman Jose Luis docencia
Sldo.Guaman Jose Luis docenciaSldo.Guaman Jose Luis docencia
Sldo.Guaman Jose Luis docenciaNoizery
 
Portfolio Sept 2015
Portfolio Sept 2015Portfolio Sept 2015
Portfolio Sept 2015Rahul Sharma
 
Historia del internet
Historia del internetHistoria del internet
Historia del internetFerBarcenas
 
Gráficas de control
Gráficas de controlGráficas de control
Gráficas de controlAlbertoHT
 

Destacado (8)

Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
 
Syllabus B.Pharm 2008-09
Syllabus B.Pharm 2008-09Syllabus B.Pharm 2008-09
Syllabus B.Pharm 2008-09
 
Xarxes socials
Xarxes socialsXarxes socials
Xarxes socials
 
Sldo.Guaman Jose Luis docencia
Sldo.Guaman Jose Luis docenciaSldo.Guaman Jose Luis docencia
Sldo.Guaman Jose Luis docencia
 
Level booklet
Level bookletLevel booklet
Level booklet
 
Portfolio Sept 2015
Portfolio Sept 2015Portfolio Sept 2015
Portfolio Sept 2015
 
Historia del internet
Historia del internetHistoria del internet
Historia del internet
 
Gráficas de control
Gráficas de controlGráficas de control
Gráficas de control
 

Similar a Node.js and Couchbase: Quick Development

Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
Full stack development with Node and NoSQL -  Austin Node.JS Group - October ...Full stack development with Node and NoSQL -  Austin Node.JS Group - October ...
Full stack development with Node and NoSQL - Austin Node.JS Group - October ...Matthew Groves
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gearsdion
 
Serverless in-action
Serverless in-actionServerless in-action
Serverless in-actionAssaf Gannon
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSGunnar Hillert
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Vendic Magento, PWA & Marketing
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
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 2017Matthew Groves
 
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 NoSQLAll Things Open
 
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 EngineRicardo Silva
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
Vertx - Reactive & Distributed
Vertx - Reactive & DistributedVertx - Reactive & Distributed
Vertx - Reactive & DistributedOrkhan Gasimov
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platformsAyush Sharma
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJosé Paumard
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworksEric Guo
 

Similar a Node.js and Couchbase: Quick Development (20)

Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
Full stack development with Node and NoSQL -  Austin Node.JS Group - October ...Full stack development with Node and NoSQL -  Austin Node.JS Group - October ...
Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Serverless in-action
Serverless in-actionServerless in-action
Serverless in-action
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)Running Vue Storefront in production (PWA Magento webshop)
Running Vue Storefront in production (PWA Magento webshop)
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
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
 
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
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
mobl
moblmobl
mobl
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
Vertx - Reactive & Distributed
Vertx - Reactive & DistributedVertx - Reactive & Distributed
Vertx - Reactive & Distributed
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworks
 

Más de Nic Raboy

Getting Started with MongoDB using Node.js
Getting Started with MongoDB using Node.jsGetting Started with MongoDB using Node.js
Getting Started with MongoDB using Node.jsNic Raboy
 
Marketing and Workflow Automation
Marketing and Workflow AutomationMarketing and Workflow Automation
Marketing and Workflow AutomationNic Raboy
 
Create a Chatbot with AWS Lex, Lambda, and HERE
Create a Chatbot with AWS Lex, Lambda, and HERECreate a Chatbot with AWS Lex, Lambda, and HERE
Create a Chatbot with AWS Lex, Lambda, and HERENic Raboy
 
Developing Amazon Alexa Skills with the Go Programming Language
Developing Amazon Alexa Skills with the Go Programming LanguageDeveloping Amazon Alexa Skills with the Go Programming Language
Developing Amazon Alexa Skills with the Go Programming LanguageNic Raboy
 
Static Site Generation with Hugo and Markdown
Static Site Generation with Hugo and MarkdownStatic Site Generation with Hugo and Markdown
Static Site Generation with Hugo and MarkdownNic Raboy
 
Powering an API with GraphQL, Golang, and NoSQL
Powering an API with GraphQL, Golang, and NoSQLPowering an API with GraphQL, Golang, and NoSQL
Powering an API with GraphQL, Golang, and NoSQLNic Raboy
 
Building a Bitcoin Hardware Wallet with Golang and a Raspberry Pi Zero
Building a Bitcoin Hardware Wallet with Golang and a Raspberry Pi ZeroBuilding a Bitcoin Hardware Wallet with Golang and a Raspberry Pi Zero
Building a Bitcoin Hardware Wallet with Golang and a Raspberry Pi ZeroNic Raboy
 
Developing Applications with Go and NoSQL
Developing Applications with Go and NoSQLDeveloping Applications with Go and NoSQL
Developing Applications with Go and NoSQLNic Raboy
 
Native to Hybrid and Back Again
Native to Hybrid and Back AgainNative to Hybrid and Back Again
Native to Hybrid and Back AgainNic Raboy
 
Developing for Offline First Mobile Experiences
Developing for Offline First Mobile ExperiencesDeveloping for Offline First Mobile Experiences
Developing for Offline First Mobile ExperiencesNic Raboy
 

Más de Nic Raboy (10)

Getting Started with MongoDB using Node.js
Getting Started with MongoDB using Node.jsGetting Started with MongoDB using Node.js
Getting Started with MongoDB using Node.js
 
Marketing and Workflow Automation
Marketing and Workflow AutomationMarketing and Workflow Automation
Marketing and Workflow Automation
 
Create a Chatbot with AWS Lex, Lambda, and HERE
Create a Chatbot with AWS Lex, Lambda, and HERECreate a Chatbot with AWS Lex, Lambda, and HERE
Create a Chatbot with AWS Lex, Lambda, and HERE
 
Developing Amazon Alexa Skills with the Go Programming Language
Developing Amazon Alexa Skills with the Go Programming LanguageDeveloping Amazon Alexa Skills with the Go Programming Language
Developing Amazon Alexa Skills with the Go Programming Language
 
Static Site Generation with Hugo and Markdown
Static Site Generation with Hugo and MarkdownStatic Site Generation with Hugo and Markdown
Static Site Generation with Hugo and Markdown
 
Powering an API with GraphQL, Golang, and NoSQL
Powering an API with GraphQL, Golang, and NoSQLPowering an API with GraphQL, Golang, and NoSQL
Powering an API with GraphQL, Golang, and NoSQL
 
Building a Bitcoin Hardware Wallet with Golang and a Raspberry Pi Zero
Building a Bitcoin Hardware Wallet with Golang and a Raspberry Pi ZeroBuilding a Bitcoin Hardware Wallet with Golang and a Raspberry Pi Zero
Building a Bitcoin Hardware Wallet with Golang and a Raspberry Pi Zero
 
Developing Applications with Go and NoSQL
Developing Applications with Go and NoSQLDeveloping Applications with Go and NoSQL
Developing Applications with Go and NoSQL
 
Native to Hybrid and Back Again
Native to Hybrid and Back AgainNative to Hybrid and Back Again
Native to Hybrid and Back Again
 
Developing for Offline First Mobile Experiences
Developing for Offline First Mobile ExperiencesDeveloping for Offline First Mobile Experiences
Developing for Offline First Mobile Experiences
 

Último

Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 

Último (20)

Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 

Node.js and Couchbase: Quick Development

  • 1. ©2015 Couchbase Inc. 1 Nic Raboy, Developer Advocate at Couchbase Quick and Easy Development with Node.js and Couchbase Server
  • 2. ©2015 Couchbase Inc. 2 About Me Nic Raboy Developer Advocate at Couchbase @nraboy (Twitter) Node.js, Android, Java, Ionic Framework, NoSQL, SQL
  • 3. ©2015 Couchbase Inc. 3 What Is Couchbase?
  • 4. ©2015 Couchbase Inc. 4 What makes Couchbase unique? 4 Performance & scalability leader Sub millisecond latency with high throughput; memory-centric architecture Multi- purpose Simplified administration Easy to deploy & manage; integrated Admin Console, single- click cluster expansion & rebalance Cache, key value store, document database, and local/mobile database in single platform Always-on availability Data replication across nodes, clusters, and data centers Enterprises choose Couchbase for several key advantages 24x365
  • 5. ©2015 Couchbase Inc. 5  Consolidated cache and database  Tune memory required based on application requirements Multi-purpose database supports many uses 5 5 Tunable built-in cache Flexible schemas with JSON Couchbase Lite  Represent data with varying schemas using JSON on the server or on the device  Index and query data with Javascript views  Light weight embedded DB for always available apps  Sync Gateway syncs data seamlessly with Couchbase Server
  • 6. ©2015 Couchbase Inc. 6 Couchbase leads in performance and scalability Auto Sharding Memory-memory XDCR Single NodeType  No manual sharding  Database manages data movement to scale out – not the user  Market’s only memory-to- memory database replication across clusters and geos  Provides disaster recover / data locality  Hugely simplifies management of clusters  Easy to scale clusters by adding any number of nodes
  • 7. ©2015 Couchbase Inc. 7 Available Couchbase Server SDKs And more…
  • 8. ©2015 Couchbase Inc. 8 Overview of the Node.js SDK
  • 9. ©2015 Couchbase Inc. 9 Node.js SDK  Uses the high performance Couchbase C library  Compatible with Node.js frameworks  Minimal coding
  • 10. ©2015 Couchbase Inc. 10 Node.js // InstantiateThe Query API var couchbase = require(“couchbase”); var myCluster = new Couchbase.Cluster(“localhost:8091”); var myBucket = myCluster.openBucket(“travel-sample”); var myQuery = couchbase.N1qlQuery();
  • 11. ©2015 Couchbase Inc. 11 Node.js function query(sql, done) { var queryToRun = myQuery.fromString(sql); myBucket.query(queryToRun, function(error, result) { if(error) { console.log(“ERROR: “, error); done(error, null); return; } done(null, result); return; }); }
  • 12. ©2015 Couchbase Inc. 12 Node.js function query(sql, done) { var queryToRun = myQuery.fromString(sql); myBucket.query(queryToRun, function(error, result) { if(error) { console.log(“ERROR: “, error); done(error, null); return; } done(null, result); return; }); }
  • 13. ©2015 Couchbase Inc. 13 Node.js function query(sql, done) { var queryToRun = myQuery.fromString(sql); myBucket.query(queryToRun, function(error, result) { if(error) { console.log(“ERROR: “, error); done(error, null); return; } done(null, result); return; }); }
  • 14. ©2015 Couchbase Inc. 14 Node.js function query(sql, done) { var queryToRun = myQuery.fromString(sql); myBucket.query(queryToRun, function(error, result) { if(error) { console.log(“ERROR: “, error); done(error, null); return; } done(null, result); return; }); }
  • 15. ©2015 Couchbase Inc. 15 Node.js function query(sql, done) { var queryToRun = myQuery.fromString(sql); myBucket.query(queryToRun, function(error, result) { if(error) { console.log(“ERROR: “, error); done(error, null); return; } done(null, result); return; }); }
  • 16. ©2015 Couchbase Inc. 16 Node.js function query(sql, done) { var queryToRun = myQuery.fromString(sql); myBucket.query(queryToRun, function(error, result) { if(error) { console.log(“ERROR: “, error); done(error, null); return; } done(null, result); return; }); }
  • 17. ©2015 Couchbase Inc. 17 Node.js Data Querying  Document lookups  Couchbase views  N1QL
  • 18. ©2015 Couchbase Inc. 18 Node.jsView Query var query =ViewQuery.from("travel", "by_name").skip(6).limit(3); myBucket.query(query, function(error, results) { for(i in results) { console.log("Row: ", results[i]); } });
  • 20. ©2015 Couchbase Inc. 20 Node.js Application Design AngularJS Client Frontend Node.js Server Backend
  • 21. ©2015 Couchbase Inc. 21 Node.js Separation of Frontend and Backend  No Jade markup  API driven  Less client and server coupling  The backend can evolve without affecting the frontend  Frontend can be extended to web as well as mobile
  • 22. ©2015 Couchbase Inc. 22 Multiple Frontends & One Backend
  • 23. ©2015 Couchbase Inc. 23 The Node.js Backend
  • 24. ©2015 Couchbase Inc. 24 Node.js Configuration // config.json { "couchbase": { "server": "127.0.0.1:8091", "bucket": "restful-sample" } }
  • 25. ©2015 Couchbase Inc. 25 Node.js Configuration // Project’s app.js file var express = require("express"); var bodyParser = require("body-parser"); var couchbase = require("couchbase"); var path = require("path"); var config = require("./config"); var app = express();
  • 26. ©2015 Couchbase Inc. 26 Node.js Configuration // app.js continued… app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); module.exports.bucket = (new couchbase.Cluster(config.couchbase.server)).openBucket(config.couchbase.bucket); app.use(express.static(path.join(__dirname, "public"))); var routes = require("./routes/routes.js")(app); var server = app.listen(3000, function () { console.log("Listening on port %s...", server.address().port); });
  • 27. ©2015 Couchbase Inc. 27 Node.js Create or Update Endpoint // routes.js app.post("/api/create", function(req, res) { if(!req.body.firstname) { return res.status(400).send({"status": "error", "message": "A firstname is required"}); } // … RecordModel.create(req.body, function(error, result) { if(error) { return res.status(400).send(error); } res.send(result); }); });
  • 28. ©2015 Couchbase Inc. 28 Node.js Get Document Endpoint // routes.js continued… app.get("/api/get", function(req, res) { if(!req.query.document_id) { return res.status(400).send({"status": "error", "message": "A document id is required"}); } RecordModel.getByDocumentId(req.query.document_id, function(error, result) { if(error) { return res.status(400).send(error); } res.send(result); }); });
  • 29. ©2015 Couchbase Inc. 29 Node.js Delete Endpoint // routes.js continued… app.post("/api/delete", function(req, res) { if(!req.body.document_id) { return res.status(400).send({"status": "error", "message": "A document id is required"}); } RecordModel.delete(req.body.document_id, function(error, result) { if(error) { return res.status(400).send(error); } res.send(result); }); });
  • 30. ©2015 Couchbase Inc. 30 Node.js Upsert Document Function // recordmodel.js RecordModel.save = function(data, callback) { var jsonObject = { type: “user”, firstname: data.firstname, lastname: data.lastname, email: data.email } var documentId = data.document_id ? data.document_id : uuid.v4(); db.upsert(documentId, jsonObject, function(error, result) { if(error) { return callback(error, null); } callback(null, {message: "success", data: result}); }); }
  • 31. ©2015 Couchbase Inc. 31 Couchbase JSON Document
  • 32. ©2015 Couchbase Inc. 32 Node.js Get Document with N1QL Function // recordmodel.js continued… RecordModel.getByDocumentId = function(documentId, callback) { var statement = "SELECT firstname, lastname, email " + "FROM `" + config.couchbase.bucket + "` AS users " + "WHERE META(users).id = $1"; var query = N1qlQuery.fromString(statement); db.query(query, [documentId], function(error, result) { if(error) { return callback(error, null); } callback(null, result); }); };
  • 33. ©2015 Couchbase Inc. 33 Node.js Delete Document Function // recordmodel.js continued… RecordModel.delete = function(documentId, callback) { db.remove(documentId, function(error, result) { if(error) { callback(error, null); return; } callback(null, {message: "success", data: result}); }); };
  • 34. ©2015 Couchbase Inc. 34 The AngularJS Frontend
  • 35. ©2015 Couchbase Inc. 35 // AngularJS app.js $scope.fetchAll = function() { $http( { method: "GET", url: "/api/getAll" } ) .success(function(result) { for(var i = 0; i < result.length; i++) { $scope.items[result[i].id] = result[i]; } }); }
  • 36. ©2015 Couchbase Inc. 36 // AngularJS app.s $scope.save = function(firstname, lastname, email) { $http( { method: "POST", url: "/api/create", data: { firstname: firstname, lastname: lastname, email: email, document_id: $stateParams.documentId } } ) }
  • 37. A Further Look AtThe Code…
  • 38. ©2015 Couchbase Inc. 38 More Complex Node.js Queries
  • 39. ©2015 Couchbase Inc. 39 Node.jsTravel Sample FlightPath.findAll = function(documentId, callback) { var statement = "SELECT faa AS fromAirport, geo " + "FROM `" + config.couchbase.bucket + "` r" + "WHERE airportname = $1 " + "UNION SELECT faa AS toAirport, geo " + "FROM `" + config.couchbase.bucket + "` r" + "WHERE airportname = $2"; var query = N1qlQuery.fromString(statement); db.query(query, [from, to], function(error, result) { if(error) { return callback(error, null); } callback(null, result); }); };
  • 40. ©2015 Couchbase Inc. 40 Node.jsTravel Sample FlightPath.findAll = function(documentId, callback) { var statement = "SELECT r.id, a.name, s.flight, s.utc, r.sourceairport, r.destinationairport, r.equipment " + "FROM `" + config.couchbase.bucket + "` r" + "UNNEST r.schedule s " + "JOIN `" + config.couchbase.bucket + "` a ON KEYS r.airlineid " + "WHERE r.sourceairport = $1AND r.destinationairport = $2AND s.day = $3 ” "ORDER BY a.name"; var query = N1qlQuery.fromString(statement); db.query(query, [queryFrom, queryTo, leave], function(error, result) { if(error) { return callback(error, null); } callback(null, result); }); };
  • 41. ©2015 Couchbase Inc. 41 Node.js Sample Applications https://github.com/couchbaselabs/try-cb-nodejs https://github.com/couchbaselabs/restful-angularjs-nodejs
  • 42. ©2015 Couchbase Inc. 42 Couchbase N1QLTutorial http://query.pub.couchbase.com/tutorial
  • 44. ©2015 Couchbase Inc. 44 Couchbase We’re Hiring! ©2014 Couchbase, Inc.
  • 45. ©2015 Couchbase Inc. 45©2014 Couchbase, Inc. ThankYou Nic Raboy Developer Advocate at Couchbase @nraboy (Twitter)

Notas del editor

  1. Couchbase has emerged as a leading NoSQL provider for number of reasons: Best in performance and scalability We’ve engineered Couchbase from the ground up for high performance and scalability Couchbase is designed to deliver sub-millisecond responsiveness with very high throughput for both reads and writes We consistently outperform competitors like MongoDB and DataStax in multiple independent benchmarks Our performance advantage is driven in large part by our memory-centric architecture, which includes an integrated managed object cache and stream-based replication Broad use case support We’re the only NoSQL provider that has consolidated distributed cache, key-value store, and a JSON-based document database in a single platform This means customers can use Couchbase for a much broader range of applications Integrated mobile solution We’re the only vendor that provides an end-to-end NoSQL mobile solution -- allows customers to easily build mobile apps that run great on or offline Includes a JSON database embedded on the device, along with a prebuilt syncing tier So apps run great on the device, even without a network connection or no connectivity at all Data on the device auto-syncs with the backend server when a connection is available Simplified administration We’ve designed Couchbase to be exceptionally easy to deploy and manage Features such as an integrated Admin Console and single-click cluster expansion & rebalance dramatically increase admin efficiency