Did you pipe stdout? console.log is synchronous when running on a terminal, but when using pipes console.log becomes asynchronous, and your program can proceed before the output is fully written.
console.log