JSON API for betherenyc.com

This week, I learned how to create a JSON API for the betherenyc data using ‘response.json(‘jsonData’)’ in NodeJS. Here’s the feed: http://betherenyc.herokuapp.com/api/allevents/

You can follow the code for the whole project on GitHub: https://github.com/michelleboisson/betherenyc

// return all event entries in json format
app.get('/api/allevents', function(request, response){</code>

// defining the fields I want to include in the json data
includeFields = ['name','desc','urlslug','date','time','place'];

// query for all events
queryConditions = {}; //empty conditions - return everything
var query = Event.find( queryConditions, includeFields);

query.sort('date',-1); //sort by most recent
query.exec(function (err, eventPosts) {

jsonData = {
'status' : 'OK',
'events' : eventPosts
}
response.json(jsonData);
});
});

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.