I have a fundamental confusion in Node.js technology. Let me explain with this small example.
I have this piece of code
setTimeout(function (){ console.log('world'); }, 2000); console.log('hello'); When I start executing this code, it immedietely prints 'hello' and after 2 seconds it prints 'world'.
Now I just want to know that if node.js is said to be the single threaded framework, then in which context or where(thread/process) this setTimeout function gets executed since the only single thread is executing the remaining code (printing world).
In case of I/O calls like DB hit, node.js uses the Libeio which in turn use threads internally. So it is not single threaded at all.
Am I right??
Please suggest.
Thanks