Does it possible to create multiple threads in a nodejs. I am not asking by using Cluster or fork or exec way. Its actually creating child process instead of thread. I want actual implementation of separate thread in node.js.
NodeJS doesn't currently support multiple threads. There's been talk about (and even work on) providing thread support, but it hasn't happened (yet?). There doesn't seem to be much impetus in that regard.
A search for "NodeJS multiple threads" will find things like JXcore, though, which claims 100% NodeJS compatibility (it's a fork with "added features"). YMMV.
As T.J. Crowder mention, you can use JXcore for this. It is an open source project now.
The simplest way to run an app multi-threaded would be:
console.log("Hello thread", process.threadId);
and you run it this way:
$ jx mt:3 hello.js
It runs 3 threads/instances inside of one process.
There are also other ways with Jxcore, to use tasks in threads.