SlideShare a Scribd company logo
Introduction to
M. Khurrum Qureshi
Sr. Software Engineer
Node’s Goal is to provide an
easy way to build scalable
network programs.
Node.js is NOT another
web framework!
But you can create a web framework using NPM modules.
Node.js is…
Web Server
TCP Server
Awesome Robot Controller
Command Line Application
Proxy Server
Streaming Server
VoiceMail Server
Music Machine
Anything that has to deal with high I/O
Node.js is
Server Side JavaScript!
Node.js is
FUN!
Why Node.js?
• Non Blocking I/O
• Based on Chrome’s V8 Engines (FAST!)
• 15,000+ Modules
• Active Community (IRC, Mailing Lists, Twitter,
Github)
• Mac, Linux and Windows (all first class citizens)
• One Language for Frontend and Backend
• JavaScript is the Language of the Web
Node.js Good Use Cases
• JSON APIs
Building light-weight REST / JSON api's is something where node.js
really shines. Its non-blocking I/O model combined with JavaScript
make it a great choice for wrapping other data sources such as
databases or web services and exposing them via a JSON interface.
• Single Page Apps
If you are planning to write an AJAX heavy single page app (think
gmail), node.js is a great fit as well. The ability to process many
requests / seconds with low response times, as well as sharing things
like validation code between the client and server make it a great
choice for modern web applications that do lots of processing on the
client.
Node.js Good Use Cases
• Shelling out to Unix Tools
With node.js still being young, it's tempting to re-invent all kinds of
software for it. However, an even better approach is tapping into the
vast universe of existing command line tools. Node's ability to spawn
thousands of child processes and treating their outputs as a stream
makes it an ideal choice for those seeking to leverage existing
software.
• Streaming Data
Traditional web stacks often treat http requests and responses as
atomic events. However, the truth is that they are streams, and many
cool node.js applications can be built to take advantage of this fact.
One great example is parsing file uploads in real time, as well as
building proxies between different data layers.
Node.js Good Use Cases
• Soft Real Time Applications
Another great aspect of node.js is the ease at which you can develop
soft real time systems. By that I mean stuff like twitter, chat software,
sport bets or interfaces to instant messaging networks.
Basic HTTP Server
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200);
res.end('Hello World');
});
server.listen(4000);
Some people use the
core http module to
build their web apps,
most use a framework
like Express
or Connect or Flatiron or Tako or Derby or Geddy or Mojito or …
Visit
http://expressjs.com/guide.html
for a detailed guide
on using Express
What is Non-Blocking I/O?
And why should I care?
Blocking I/
270ms = SUM(user, activities, leaderboard)
// Get User – 20ms
$query = 'SELECT * FROM users WHERE id = ?';
$users = query($query, array($id));
print_r($users);
// Get Activities – 100ms
$query = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50';
$activities = query($query);
print_r($activities);
// Get Leader Board – 150ms
$query = 'SELECT count(points) as total, user_id FROM activities LIMIT 50';
$leader_board = query($query);
Non-Blocking I/
150ms = MAX(user, activities, leaderboard)
// Get User – 20ms
var query = 'SELECT * FROM users WHERE id = ?';
db.query(query, [userId], function (err, results) {
console.log(results);
});
// Get Activities – 100ms
var query = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50';
db.query(query, function (err, results) {
console.log(results);
});
// Get Leader Board – 150ms
var query = 'SELECT count(points) as total, user_id FROM activities LIMIT 50';
db.query(query, function (err, results) {
console.log(results);
});
The most jarring thing
about Server Side JavaScript
is thinking in callbacks
The Node Callback Pattern
awesomeFunction(arg, function (err, data) {
if (err) {
// Handle Error
}
// Do something awesome with results.
});
• Error first then success… ALWAYS!
• Because this is the de-facto standard 99.99999% of the time
you will be able to guess how a Node library will work.
Callbacks are the Devil’s Work!
Don’t go down this rabbit hole…
One of the biggest mistakes is to get yourself in
to callback hell by nesting callbacks inside of
callbacks inside of more callbacks.
var userQuery = 'SELECT * FROM users WHERE id = ?';
var activityQuery = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50';
var leaderBoardQuery = 'SELECT count(points) as total, user_id FROM activities LIMIT 50';
db.query(userQuery, [id], function (userErr, userResults) {
db.query(activityQuery, function (activityErr, activityResults) {
db.query(leaderBoardQuery, function (leaderBoardErr, leaderBoardResults) {
// Do something here
});
});
});
Avoiding Callback Hell
• Keep your code shallow
• Break up your code into small chunks
• Use a sequential library like async
• Visit http://callbackhell.com
Async to the rescue!
var async = require('async');
var db = require(’db');
function getUser (callback) {
var query = 'SELECT * FROM users WHERE id = ?';
db.query(query, [userId], callback);
}
function getActivities (callback) {
var query = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50';
db.query(query, callback);
}
function getLeaderBoard (callback) {
var query = 'SELECT count(points) as total, user_id FROM activities LIMIT 50';
db.query(query, callback);
}
var tasks = [getUser, getActivities, getLeaderBoard];
async.parallel(tasks, function (err, results) {
var user = results[0];
var activities = results[1];
var leaderBoard = results[2];
});
Visit
https://github.com/caolan/async
for a detailed guide on using the async module.
Async provides several useful
patterns for asynchronous control
flow including: parallel, series,
waterfall, auto and queue.
The Node Package Manager
otherwise know as… NPM
It’s how you harness the
awesomeness of the
Node.js community!
Using NPM
It’s standard practice to install modules locally for your current project.
Modules are installed in the ./node_modules in the current directory.
To Install a new module
npm install <module>
To find a module in the NPM repository
npm search <search string>
To list the modules (and their dependencies) in the current project
npm list
To see module details
npm info <module>
DON’T INSTALL
MODULES GLOBALLY!
Unless they are tools like node-dev, jake, express, minify-js
OR linked development modules but more on that later.
NPM is awesome sauce!
Visit
https://npmjs.org
for more details about NPM and to
browse the current NPM Repository
Node.js Modules
• async
• connect
• express
• mongodb-
native-driver
• request
• apn
• ql.io-engine
• pem
• winston
• winston-
mongodb
Node.js Modules
• node-sql
• nodemailer
• connect-http-
signature
• http-signature
• underscore
• file-utils
• validator
• mongoskin
• passport.Js
• yql
Node.js Modules
• node-gcm
• forever
• mongodb_s3_b
ackup
• nconf
• node-sqlserver
• Socket-io
• generic-pool
• And many
others
Deployment Platforms
• Amazon EC2
• Windows Azure
• Heroku
• Joynet
• Nodejistu
Questions?
Introduction to
NoSql
• Non-Relational
• Horizontally Scalable
• Distributed
• Schema-Free
• Open-Source
• Replication Support
• Simple API
NoSql Flavours
• Key-value Store.
• Graph
• Big Table
• Document Store
mongoDB Overview
• Document Database
– Documents (objects) map nicely to programming language data types.
– Embedded documents and arrays reduce need for joins.
– Dynamic schema
• High Performance
– Embedding makes reads and writes fast.
– Indexes can include keys from embedded documents and arrays.
– Optional streaming writes (no acknowledgments).
• High Availability
– Replicated servers with automatic master failover.
mongoDB Overview
• Easy Scalability
– Automatic sharding distributes collection data across machines.
mongoDB Data Model
• MongoDB instance hosts a number of databases.
• A database holds a set of collections.
• A collection holds a set of documents.
• A document is a set of key-value pairs.
• Documents have dynamic schema.
Document Structure
• Data is stored in the form of JSON data.(Which
internally stored as BSON)
{
"_id" : ObjectId("4ccbfc75bd163019417c27f8"),
"title": “Hello World! ",
"author": {
"firstname": "Joe",
"lastname": "Bloggs"
},
"tags": ["test", "foo", "bar"]
}
Key mongoDB Features
• Flexibility
• Power
• Speed/Scaling
• Ease of use
Questions?

More Related Content

What's hot

Introduction to Javascript By Satyen
Introduction to Javascript By  SatyenIntroduction to Javascript By  Satyen
Introduction to Javascript By Satyen
Satyen Pandya
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
Jeff Kunkle
 
Node.js an introduction
Node.js   an introductionNode.js   an introduction
Node.js an introductionMeraj Khattak
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
Arvind Devaraj
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
cacois
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
David Boyer
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
Ndjido Ardo BAR
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
Yukti Kaura
 
Node js presentation
Node js presentationNode js presentation
Node js presentationmartincabrera
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
Christian Joudrey
 
Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
Ganesh Iyer
 
node.js dao
node.js daonode.js dao
node.js dao
Vladimir Miguro
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
Fabien Vauchelles
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
fakedarren
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
jguerrero999
 
NodeJS
NodeJSNodeJS
NodeJS
LinkMe Srl
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
Naresh Chintalcheru
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Dinh Pham
 

What's hot (20)

Introduction to Javascript By Satyen
Introduction to Javascript By  SatyenIntroduction to Javascript By  Satyen
Introduction to Javascript By Satyen
 
Node.js Explained
Node.js ExplainedNode.js Explained
Node.js Explained
 
Node.js an introduction
Node.js   an introductionNode.js   an introduction
Node.js an introduction
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
Nodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
 
node.js dao
node.js daonode.js dao
node.js dao
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
NodeJS
NodeJSNodeJS
NodeJS
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
 

Viewers also liked

Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
christkv
 
Test Automation using Ruby
Test Automation using Ruby Test Automation using Ruby
Test Automation using Ruby
Sla Va
 
Knonex
KnonexKnonex
EVRYTHNG: Concepts, technologies and applications for connecting physical obj...
EVRYTHNG: Concepts, technologies and applications for connecting physical obj...EVRYTHNG: Concepts, technologies and applications for connecting physical obj...
EVRYTHNG: Concepts, technologies and applications for connecting physical obj...
EVRYTHNG
 
5 Years of Web of Things Workshops
5 Years of Web of Things Workshops5 Years of Web of Things Workshops
5 Years of Web of Things Workshops
Dominique Guinard
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Best node js course
Best node js courseBest node js course
Best node js course
bestonlinecoursescoupon
 
7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications
David Mitzenmacher
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 

Viewers also liked (9)

Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
 
Test Automation using Ruby
Test Automation using Ruby Test Automation using Ruby
Test Automation using Ruby
 
Knonex
KnonexKnonex
Knonex
 
EVRYTHNG: Concepts, technologies and applications for connecting physical obj...
EVRYTHNG: Concepts, technologies and applications for connecting physical obj...EVRYTHNG: Concepts, technologies and applications for connecting physical obj...
EVRYTHNG: Concepts, technologies and applications for connecting physical obj...
 
5 Years of Web of Things Workshops
5 Years of Web of Things Workshops5 Years of Web of Things Workshops
5 Years of Web of Things Workshops
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
Best node js course
Best node js courseBest node js course
Best node js course
 
7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 

Similar to Intro to node and mongodb 1

Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
async_io
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
Yoann Gotthilf
 
Node azure
Node azureNode azure
Node azure
Emanuele DelBono
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
FITC
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
Richard Rodger
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
soft-shake.ch
 
Scalable server component using NodeJS & ExpressJS
Scalable server component using NodeJS & ExpressJSScalable server component using NodeJS & ExpressJS
Scalable server component using NodeJS & ExpressJS
Andhy Koesnandar
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
Ohad Kravchick
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
Shubhra Kar
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
Jibanananda Sana
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 

Similar to Intro to node and mongodb 1 (20)

Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
Node azure
Node azureNode azure
Node azure
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Scalable server component using NodeJS & ExpressJS
Scalable server component using NodeJS & ExpressJSScalable server component using NodeJS & ExpressJS
Scalable server component using NodeJS & ExpressJS
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Intro to node and mongodb 1

  • 1. Introduction to M. Khurrum Qureshi Sr. Software Engineer
  • 2. Node’s Goal is to provide an easy way to build scalable network programs.
  • 3. Node.js is NOT another web framework! But you can create a web framework using NPM modules.
  • 4. Node.js is… Web Server TCP Server Awesome Robot Controller Command Line Application Proxy Server Streaming Server VoiceMail Server Music Machine Anything that has to deal with high I/O
  • 7. Why Node.js? • Non Blocking I/O • Based on Chrome’s V8 Engines (FAST!) • 15,000+ Modules • Active Community (IRC, Mailing Lists, Twitter, Github) • Mac, Linux and Windows (all first class citizens) • One Language for Frontend and Backend • JavaScript is the Language of the Web
  • 8. Node.js Good Use Cases • JSON APIs Building light-weight REST / JSON api's is something where node.js really shines. Its non-blocking I/O model combined with JavaScript make it a great choice for wrapping other data sources such as databases or web services and exposing them via a JSON interface. • Single Page Apps If you are planning to write an AJAX heavy single page app (think gmail), node.js is a great fit as well. The ability to process many requests / seconds with low response times, as well as sharing things like validation code between the client and server make it a great choice for modern web applications that do lots of processing on the client.
  • 9. Node.js Good Use Cases • Shelling out to Unix Tools With node.js still being young, it's tempting to re-invent all kinds of software for it. However, an even better approach is tapping into the vast universe of existing command line tools. Node's ability to spawn thousands of child processes and treating their outputs as a stream makes it an ideal choice for those seeking to leverage existing software. • Streaming Data Traditional web stacks often treat http requests and responses as atomic events. However, the truth is that they are streams, and many cool node.js applications can be built to take advantage of this fact. One great example is parsing file uploads in real time, as well as building proxies between different data layers.
  • 10. Node.js Good Use Cases • Soft Real Time Applications Another great aspect of node.js is the ease at which you can develop soft real time systems. By that I mean stuff like twitter, chat software, sport bets or interfaces to instant messaging networks.
  • 11. Basic HTTP Server var http = require('http'); var server = http.createServer(function (req, res) { res.writeHead(200); res.end('Hello World'); }); server.listen(4000);
  • 12. Some people use the core http module to build their web apps, most use a framework like Express or Connect or Flatiron or Tako or Derby or Geddy or Mojito or …
  • 14. What is Non-Blocking I/O? And why should I care?
  • 15. Blocking I/ 270ms = SUM(user, activities, leaderboard) // Get User – 20ms $query = 'SELECT * FROM users WHERE id = ?'; $users = query($query, array($id)); print_r($users); // Get Activities – 100ms $query = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50'; $activities = query($query); print_r($activities); // Get Leader Board – 150ms $query = 'SELECT count(points) as total, user_id FROM activities LIMIT 50'; $leader_board = query($query);
  • 16. Non-Blocking I/ 150ms = MAX(user, activities, leaderboard) // Get User – 20ms var query = 'SELECT * FROM users WHERE id = ?'; db.query(query, [userId], function (err, results) { console.log(results); }); // Get Activities – 100ms var query = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50'; db.query(query, function (err, results) { console.log(results); }); // Get Leader Board – 150ms var query = 'SELECT count(points) as total, user_id FROM activities LIMIT 50'; db.query(query, function (err, results) { console.log(results); });
  • 17. The most jarring thing about Server Side JavaScript is thinking in callbacks
  • 18. The Node Callback Pattern awesomeFunction(arg, function (err, data) { if (err) { // Handle Error } // Do something awesome with results. }); • Error first then success… ALWAYS! • Because this is the de-facto standard 99.99999% of the time you will be able to guess how a Node library will work.
  • 19. Callbacks are the Devil’s Work! Don’t go down this rabbit hole… One of the biggest mistakes is to get yourself in to callback hell by nesting callbacks inside of callbacks inside of more callbacks. var userQuery = 'SELECT * FROM users WHERE id = ?'; var activityQuery = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50'; var leaderBoardQuery = 'SELECT count(points) as total, user_id FROM activities LIMIT 50'; db.query(userQuery, [id], function (userErr, userResults) { db.query(activityQuery, function (activityErr, activityResults) { db.query(leaderBoardQuery, function (leaderBoardErr, leaderBoardResults) { // Do something here }); }); });
  • 20. Avoiding Callback Hell • Keep your code shallow • Break up your code into small chunks • Use a sequential library like async • Visit http://callbackhell.com
  • 21. Async to the rescue! var async = require('async'); var db = require(’db'); function getUser (callback) { var query = 'SELECT * FROM users WHERE id = ?'; db.query(query, [userId], callback); } function getActivities (callback) { var query = 'SELECT * FROM activities ORDER BY timestamp LIMIT 50'; db.query(query, callback); } function getLeaderBoard (callback) { var query = 'SELECT count(points) as total, user_id FROM activities LIMIT 50'; db.query(query, callback); } var tasks = [getUser, getActivities, getLeaderBoard]; async.parallel(tasks, function (err, results) { var user = results[0]; var activities = results[1]; var leaderBoard = results[2]; });
  • 22. Visit https://github.com/caolan/async for a detailed guide on using the async module. Async provides several useful patterns for asynchronous control flow including: parallel, series, waterfall, auto and queue.
  • 23. The Node Package Manager otherwise know as… NPM It’s how you harness the awesomeness of the Node.js community!
  • 24. Using NPM It’s standard practice to install modules locally for your current project. Modules are installed in the ./node_modules in the current directory. To Install a new module npm install <module> To find a module in the NPM repository npm search <search string> To list the modules (and their dependencies) in the current project npm list To see module details npm info <module>
  • 25. DON’T INSTALL MODULES GLOBALLY! Unless they are tools like node-dev, jake, express, minify-js OR linked development modules but more on that later.
  • 26. NPM is awesome sauce! Visit https://npmjs.org for more details about NPM and to browse the current NPM Repository
  • 27. Node.js Modules • async • connect • express • mongodb- native-driver • request • apn • ql.io-engine • pem • winston • winston- mongodb
  • 28. Node.js Modules • node-sql • nodemailer • connect-http- signature • http-signature • underscore • file-utils • validator • mongoskin • passport.Js • yql
  • 29. Node.js Modules • node-gcm • forever • mongodb_s3_b ackup • nconf • node-sqlserver • Socket-io • generic-pool • And many others
  • 30. Deployment Platforms • Amazon EC2 • Windows Azure • Heroku • Joynet • Nodejistu
  • 33. NoSql • Non-Relational • Horizontally Scalable • Distributed • Schema-Free • Open-Source • Replication Support • Simple API
  • 34. NoSql Flavours • Key-value Store. • Graph • Big Table • Document Store
  • 35. mongoDB Overview • Document Database – Documents (objects) map nicely to programming language data types. – Embedded documents and arrays reduce need for joins. – Dynamic schema • High Performance – Embedding makes reads and writes fast. – Indexes can include keys from embedded documents and arrays. – Optional streaming writes (no acknowledgments). • High Availability – Replicated servers with automatic master failover.
  • 36. mongoDB Overview • Easy Scalability – Automatic sharding distributes collection data across machines.
  • 37. mongoDB Data Model • MongoDB instance hosts a number of databases. • A database holds a set of collections. • A collection holds a set of documents. • A document is a set of key-value pairs. • Documents have dynamic schema.
  • 38. Document Structure • Data is stored in the form of JSON data.(Which internally stored as BSON) { "_id" : ObjectId("4ccbfc75bd163019417c27f8"), "title": “Hello World! ", "author": { "firstname": "Joe", "lastname": "Bloggs" }, "tags": ["test", "foo", "bar"] }
  • 39. Key mongoDB Features • Flexibility • Power • Speed/Scaling • Ease of use