I have made a Nodejs and angular2 app where i need to integrate them to Neo4j app. I am able to hit the Database from my NodeJS code coming from Angular2 but then i am unabl
You can send the response back ONLY once, you have an asynchronous operation running while you send the response "It works" and again sending the response with actual data.
res.send
sets response headers to object which should ideally happen once during the request lifecycle.
function tmsServer(req, res) {
session
.run('MATCH (n) RETURN n LIMIT 5')
.then(function (result){
result.records.forEach(function(record){
// This will execute only when the promise is resolved and data is returned from database.
res.send(result); // (RES02)
});
})
.catch(function(err){
console.log("inside catch = "+err);
})
res.send('It Works'); // (RES01) <--- This runs before RES02
session.close();
}
The solution to your answer is to remove RES01
.