aseemk / node-neo4j-template

A template app for using Neo4j from Node.js.
http://node-neo4j-template.herokuapp.com/
216 stars 92 forks source link

Returning data-only JSON #12

Closed cleercode closed 10 years ago

cleercode commented 10 years ago

I'm trying to create a server of this general format that returns JSON (for use by a client) instead of rendering HTML. However, it returns the JSON with all the metadata from both node-neo4j and Neo4j itself. All I want is the data. This is relatively easy to filter at the top level (ex. routes/users.js) except for functions returning multiple results like User.getAll. I tried modifying the lower level models/users.js, but then it became evident that the User prototype wrapper is useful for combined queries like a User.get followed by user.getFollowingAndOthers. I can think of some ways to rearchitect this for this use case, but any thoughts on how to do it in a sane way?

aseemk commented 10 years ago

Sorry for the delay, @cleercode, but yep, should be as easy as this:

User.prototype.toJSON = function () {
    return this._node.data;
};

See if that works for you?