How to use the output from a function of a module in another module

I have a mdoule, where i create a db connection and a function which runs a query. I want to use the output of this query in another module. How do I do this?

The query is supposed to return the value from the key-value pair (hello:world). However, everytime I try to use the variable in another module, I end up with "true" instead of "world".

my code is here https://github.com/rishavs/RedisDbConnect

I want to call the getValue function from app.js and maybe console.log(db.getValue()) the output.

You can't return value from async function like from sync. You need to use callback way. Modify your code like this:

getValue function:

var getValue = function(cb) {
    dbConnection.get("hello", function (err, reply) {
        var val = reply ? reply.toString() : null;
        cb(err, val);
    });
};

Controller:

app.get('/json', function(req, res, next) {
    res.contentType('application/json');
    db.getValue(function(err, val) {
        if (err) return next(err);
        res.send(val);  
    });
});