Tuesday, September 17, 2013

NodeJS | Passing an object as function parameter

NodeJS | Passing an object as function parameter

I've had a small problem I couldn't overcome this week, I'm trying to pass
a JSON object as a parameter in a function but it always tells me that I
can't do that, but I don't want to end up sending the 50 values separately
from my json object.
Here is the set up on my app, this is working as intended with express :
app.get('/', routes.index);
Here is the routing index from the previous line of code (Note that I'm
using jade for rendering and I'm using the next function to pass
parameters to it like the name in this one :
exports.index = function(req, res){
getprofile.profileFunc(function(result) {
res.render('index', { name: result });
});
};
Next it calls the function profileFunc from getprofile :
var profileFunc = function(callback) {
var sapi = require('sapi')('rest');
sapi.userprofile('name_here', function(error, profile) {
var result = [profile.data.name];
callback.apply(null, result);
});
};
exports.profileFunc = profileFunc;
Note that I was only able to pass a string result and have it displayed in
the jade render, what I want to do is pass the profile object to use it in
the render to display name, age, birthday but I can't get it to work, it
will either pass a undefined object or not pass.
Thanks for taking time to read this.

No comments:

Post a Comment