Sign up ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

My code responds to a request with data from an external site – it retrieves data from the internet that gets packaged with any response.

I am a javascript beginner and am not used to asynchronous programming. Can someone tell me if I am doing this correctly:

var Hapi = require('hapi');
var Handlebars = require('handlebars');
var ical = require('ical');

// Set up server here:
// ...

// Get data from the web:
var ical_url = 'url_here';

function fmt_events(data){
  var eventData = {events:[]}
  // format data and push onto eventData.events
  return eventData;
}

// here is where I need feedback:
server.route({
  method: 'GET',
  path: '/',
  handler: function (request, reply) {
    function events_callback(err, data) {
      var eventData = fmt_events(data);
      reply.view('index', {
        title: 'Title',
        events: eventData
      });
    }
    ical.fromURL(ical_url, {}, events_callback);
  }
});
share|improve this question
    
What's not happening? Debug the err and data in events_callback. –  Adrian Lynch Jan 9 at 14:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.