How to return something async with require?

I'm a little new to this so bear with me...

app.js:

var testVariable = require('./test');
console.log(testVariable);

test.js:

setTimeout(function() {
    exports.something = "HELLO!";
}, 10000);

In this scenario, the output is {}. If exports.something = "HELLO!"; is moved outside the setTimeout, the output is { something: 'HELLO' }.

I'm trying to connect to a DB and it's taking a second as you can imagine. How can I return something that takes a little while to process to app.js?

You can't.

require is synchronous, node initially had asynchronous require but it was dropped because people ended up abusing it, and it was not well maintained.

I suggest you do something like

exports.something = promise;

And return a promise for the value, or a callback handler.

The simplest implementation could be

var callback=function(){},fired=false,data;
exports.handle = function(cb){
    callback = cb;
    if(fired === true){ //already fired once
      cb(data);//fire again
    }
});

setTimeout(function() {
    cb("HELLO!");
    fired = true;
    data = "HELLO!";
}, 10000);

Then you could use

require("myModule").handle(function(data){
   //work with data
});

The idea is that instead of returning the value, you're returning a function to execute when the value is ready on the value. (Also, I've included some boilerplate so that it executes if the callback finished before the handler was assigned)