Refined node.js logic