Trying to understand the API

74 views
Skip to first unread message

Corey Subnet

unread,
Jun 11, 2014, 8:03:54 PM6/11/14
to node-...@googlegroups.com
Hi all, 

I'm fairly new to programming so forgive me if I ask an overly simplistic question, but I have no idea how to read the API documentation.

I was trying to put together a little server app that finds the shortest path between two nodes. I POST the data to the function "shortestpath" and it eventually filters through to a jade view. However, the string that is finally passed onto jade looks like [object Object]. When I JSON.stringify it, it ends up looking like:

 [{"_start":{"_nodeNeo4j":{"version":"1.1.0","constructor":"Node"},"_data":{"self":"http://localhost:7474/db/data/node/7056"}},"_nodes":

et cetera.

I noticed from the API that the path class uses a few properties like length and start. These would be very helpful to me if I were able to fetch them. "(node) start" does not really help me do that.

Here is my code:

var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://localhost:7474');



function resultants(neoPath, res){
res.render("results",{path: neoPath});
console.log("logging the path: ");
console.log(neoPath);
res.end('end');
}


function talkToNeo (nodeone, nodetwo, res) {
var params = {
};
var query = [
    'MATCH (a {xml_id:"'+ nodeone +'"}),(b {xml_id:"' + nodetwo + '"}),',
    'p = shortestPath((a)-[*..15]-(b))',
    'RETURN (p)' 
   ].join('\n');
console.log(query);
db.query(query, params, function (err, results) {
if (err) throw err;
var neoPath = results.map(function (result){
return result['p'];
});
console.log("this is the value of neoPath");
console.log(neoPath);
resultants(neoPath, res);
});
};


exports.shortestpath= function (req, res) {
console.log("exports at shortestpath called");
if (req.method == 'POST'){
console.log("if statement worked");
var nodeone = req.body.nodeone;
var nodetwo = req.body.nodetwo;
console.log(nodeone);

talkToNeo(nodeone, nodetwo, res);

};
};




Reply all
Reply to author
Forward
0 new messages