replace deprecated process.nextTick with setImmediate