There are 2 good libraries for creating threads in Node JS even though Node JS is event-driven single threaded. These libraries use Web Workers standard by W3C:
https://www.w3.org/TR/workers/

Links:
https://www.npmjs.com/package/webworker-threads
https://www.npmjs.com/package/threads

Module ‘webworker-threads‘ uses a single Node JS process with background web workers. Module ‘threads‘ uses multiple Node JS processes created from child_process core module, this slows down very much when creating new thread as a new Node JS process must be loaded and run (or even needs to compile some code?).

webworker-threads: fast, but only raw pure JavaScript in thread code.
threads: slow (load new process), taking RAM (each process takes 1 Node JS instance), but comes with full Node JS features.

Example of using ‘webworker-threads’ module:

var worker = require("webworker-threads").Worker;
 
var Worker1 = new worker(function(){
  postMessage("I'm working before postMessage('Jim').");
  this.onmessage = function(Event) {
    postMessage("Hi "+Event.data);
    self.close();
  };
});

Worker1.onmessage = function(Event) {
  console.log("Worker said: "+Event.data);
};

Worker1.postMessage("Jim");

Example of using ‘threads’ module:

"use strict";

//library modules
var threads = require("threads");

//create thread
var Thread1 = threads.spawn(function(Input,Send){
  Send(Input*2);
  Send(Input*Input);
});

Thread1.on("message",function(Data){
  console.log(Data);
});

Thread1.send(1);
Advertisements