Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my app.js

var employees = require('../models/employees');

employees.read(req.params.id, function(body) {
    console.log(body.firstName);
});

in my models/employees

var request = require('request');

var employees = {

    read: function(id, callback) {
        request
            .get('http://api.mysite.com/employees/' + id, function(error, response, body) {
                body = JSON.parse(body);
                return callback(body);
            })
    },
};

module.exports = employees;

this works. (returns the employee name correctly) but I´m not sure if this is the correct (async) way of getting data from an api and displaying it.

share|improve this question

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.