If not, then calling it multi-threaded is misleading to a programmer who needs such things, and instead you'll need to find a more accurate word.
process.env.UV_THREADPOOL_SIZE = 10;
function startOne() {
const start = Date.now()
require('crypto').pbkdf2(String(start), 'secretSalt', 100000, 512, 'sha512', (error, result) => {
console.log(`${result.length}b took ${Date.now() - start}ms`);
startOne();
});
}
for (let i = 0; i < 10; i++) startOne();
You can use htop or another tool of your choice to confirm this is the case.If you are talking more generally about anything we can run within Node.JS, is using Node.JS user-facing APIs and works without doing any modifications to Node.JS, the answer is yes. You can easily achieve that with node's native module support, and I would encourage you to do so over committing the folly of doing anything CPU intensive in JS.
That is if you manage to find any CPU intensive task that isn't already handled by node built-ins or some library out there.
Edit:
Now you may say: "Ahah! You can't use threads using [limited usage of node]. Also threads must be usable for arbitrary workloads in order to consider a thing multi-threaded. Node.js is single-threaded!"
I just can't argue with that. It's just a matter of opinions now about what makes a thing/environment single-threaded, and what makes it multi-threaded.
To me it's simple: [x] Thing uses multiple threads to perform work.
Yes, delegating to the C++ modules in the background, which do support multi-threading.
These modules have nothing to do with Node directly so meme stays - node itself is single-threaded no matter how you spin this off.
Eh, what are these if not part of node?
What kind of definition are you applying so that a thing is suddenly no longer the sum of its parts?
Edit: JavaScript may be single threaded. Node.JS is not. JavaScript is but a part of Node.JS.
True, your JS code all runs in a single thread, but all the heavy lifting is behind asynchronous interfaces, delegating the work to a threadpool in the background.
What a Node.JS application really is, is a supervisor thread (your JS code) giving work for a bunch of worker threads. Doesn't sound very single threaded to me.