Umesh_IoT Umesh_IoT - 1 year ago 97
Node.js Question

How to create a Node JS constructor to initialize a callback function

I am new to Node JS + Javascript. I have a module where I expect it to work as a constructor and initialize some data. And expect those data(array) to be available when I require it from another module. I referred couple of stackoverflow questions and couldn't figure it out.
I have mentioned those links below. Appreciate if anyone can help to resolve this.

Initialize a module when it's required

Node.js - use of module.exports as a constructor

var answers = function() {
this.getAnswers = function(callback) {
conversations.getRequestData(function(conArr) {
var results = [];
// some code here

module.exports = answers

Answer Source

This is your independent module with callback function and getting the output in other file:

exports.answers = function(callback){

var test = requires('./test');
    method: 'GET',
    path: '/testing_exports',
    handler: function (req, reply) {
            console.log(resp); // your callback result
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download