You're not calling the function with the right context (this
in the function). You can fix it by replacing
exportFunc.query("myquery", res.end);
with
exportFunc.query("myquery", res.end.bind(res));
or
exportFunc.query("myquery", function(){ res.end() });