SlideShare a Scribd company logo
Use IBM Graph from NodeJS
IBM-GRAPH-CLIENT
https://www.npmjs.com/package/ibm-graph-client
SIGN	UP	ON	BLUEMIX.NET	AND	LOOK	FOR	IBM
GRAPH
CREATE	AN	INSTANCE
INIT	SESSION
# Change the credentials to reflect your `apiURL`, `username`, and `password` and test the code in your instance.
{
"credentials": {
"apiURL": "https://ibmgraph-alpha.ng.bluemix.net/a261eac3-6956-4185-a789-8e24c475e89b/g",
"username": "575fd2b0-c011-4b94-82cf-43244b44f3a8",
"password": "aca0d011-26f5-485d-a446-182750278a27"
}
};
var ibmGraph= require('ibm-graph-client');
var g = new ibmGraph(instance.credentials);
g.session(function(err, data) {
if (err) {
console.log(err);
} else {
g.config.session = data;
console.log("Your session token is " + data);
}
});
CREATE	A	GRAPH
var graph; // graph name
g.graphs().create(function(err, data){
if (err) {
console.log("Something went wrong: ");
console.log(err);
} else {
graph = data.graphId;
console.log('Graph created: ' + data.graphId);
}
});
GET	ALL	GRAPHS
g.graphs().get(function(err, data){
if (err) {
console.log(err);
}
console.log(data);
});
DEFINE	A	SCHEMA
var schema = {
"propertyKeys": [
{"name": "name", "dataType": "String", "cardinality": "SINGLE"},
],
"vertexLabels": [
{"name": "person"},
],
"edgeLabels": [
{"name": "tweets", "multiplicity": "MULTI"},
],
"vertexIndexes": [
{"name": "vByName", "propertyKeys": ["name"], "composite": true, "unique": true},
],
"edgeIndexes" :[
{"name": "eByTime", "propertyKeys": ["time"], "composite": true, "unique": false}
]
}
ADD	A	SCHEMA
#Point your config to the new graph you just created
g.config.url = g.config.url.substr(0, g.config.url.lastIndexOf('/') + 1) + graph;
g.schema().set(schema, function(err, data){
if (err) {
console.log(err);
}
console.log(JSON.stringify(data));
});
CREATE	SOME	VERTEXES	AND	EDGES
gremlin = {
gremlin: "
def david = graph.addVertex(T.label, 'person', 'name', 'David', 'verified', false);
def browniesTweet = graph.addVertex(T.label, 'tweet', 'tweet', 'I love brownies #baking @Joseph', 'sentiment', 'loving', 'tone', 'e
david.addEdge('tweets', browniesTweet);
browniesTweet.addEdge('hashes', bakingHashtag);
browniesTweet.addEdge('mentions', joseph);
",
bindings: {}
}
g.gremlin(gremlin, function(err,data){
if (err) {
console.log(err);
}
console.log(JSON.stringify(data));
});
QUERY	THE	GRAPH
gremlin = {
"gremlin": "graph.traversal().V().hasLabel('person').has('name', name).outE('favorites').inV();",
"bindings": { "name": "Kamal" }
}
g.gremlin(gremlin, function(err,data){
if (err) {
console.log('Error: ' + err);
}
console.log(JSON.stringify(data));
});

More Related Content

Recently uploaded (20)

PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Adobe Premiere Pro Crack / Full Version / Free Download
hashhshs786
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Adobe Premiere Pro Crack / Full Version / Free Download
hashhshs786
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 

Featured (20)

PDF
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
PDF
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
PDF
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PDF
Skeleton Culture Code
Skeleton Technologies
 
PDF
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
PDF
Content Methodology: A Best Practices Report (Webinar)
contently
 
PPTX
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
PDF
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
PDF
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
PDF
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
PDF
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
PDF
Getting into the tech field. what next
Tessa Mero
 
PDF
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
PDF
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
PDF
Introduction to Data Science
Christy Abraham Joy
 
PDF
Time Management & Productivity - Best Practices
Vit Horky
 
PDF
The six step guide to practical project management
MindGenius
 
PDF
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
PDF
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
PDF
12 Ways to Increase Your Influence at Work
GetSmarter
 
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
GetSmarter
 
Ad

Use IBM Graph from NodeJS

  • 5. INIT SESSION # Change the credentials to reflect your `apiURL`, `username`, and `password` and test the code in your instance. { "credentials": { "apiURL": "https://ibmgraph-alpha.ng.bluemix.net/a261eac3-6956-4185-a789-8e24c475e89b/g", "username": "575fd2b0-c011-4b94-82cf-43244b44f3a8", "password": "aca0d011-26f5-485d-a446-182750278a27" } }; var ibmGraph= require('ibm-graph-client'); var g = new ibmGraph(instance.credentials); g.session(function(err, data) { if (err) { console.log(err); } else { g.config.session = data; console.log("Your session token is " + data); } });
  • 6. CREATE A GRAPH var graph; // graph name g.graphs().create(function(err, data){ if (err) { console.log("Something went wrong: "); console.log(err); } else { graph = data.graphId; console.log('Graph created: ' + data.graphId); } });
  • 7. GET ALL GRAPHS g.graphs().get(function(err, data){ if (err) { console.log(err); } console.log(data); });
  • 8. DEFINE A SCHEMA var schema = { "propertyKeys": [ {"name": "name", "dataType": "String", "cardinality": "SINGLE"}, ], "vertexLabels": [ {"name": "person"}, ], "edgeLabels": [ {"name": "tweets", "multiplicity": "MULTI"}, ], "vertexIndexes": [ {"name": "vByName", "propertyKeys": ["name"], "composite": true, "unique": true}, ], "edgeIndexes" :[ {"name": "eByTime", "propertyKeys": ["time"], "composite": true, "unique": false} ] }
  • 9. ADD A SCHEMA #Point your config to the new graph you just created g.config.url = g.config.url.substr(0, g.config.url.lastIndexOf('/') + 1) + graph; g.schema().set(schema, function(err, data){ if (err) { console.log(err); } console.log(JSON.stringify(data)); });
  • 10. CREATE SOME VERTEXES AND EDGES gremlin = { gremlin: " def david = graph.addVertex(T.label, 'person', 'name', 'David', 'verified', false); def browniesTweet = graph.addVertex(T.label, 'tweet', 'tweet', 'I love brownies #baking @Joseph', 'sentiment', 'loving', 'tone', 'e david.addEdge('tweets', browniesTweet); browniesTweet.addEdge('hashes', bakingHashtag); browniesTweet.addEdge('mentions', joseph); ", bindings: {} } g.gremlin(gremlin, function(err,data){ if (err) { console.log(err); } console.log(JSON.stringify(data)); });
  • 11. QUERY THE GRAPH gremlin = { "gremlin": "graph.traversal().V().hasLabel('person').has('name', name).outE('favorites').inV();", "bindings": { "name": "Kamal" } } g.gremlin(gremlin, function(err,data){ if (err) { console.log('Error: ' + err); } console.log(JSON.stringify(data)); });