@PitaJ is correct. The database query is asynchronous, so you will need to use a callback: function queryDb(id, callback) { // query db callback(err, price); }