In Node.js, you can use the os
module to get the number of CPUs available on the system. The os.cpus()
method returns an array of CPU information objects, so you can simply check the length of that array to get the number of CPUs.
Here's some sample code:
index.tsx112 chars5 lines
The cpuCount
variable will contain the number of CPUs detected by the os
module. Note that this number may not correspond exactly to the number of physical CPUs in the system, as some CPUs may have multiple cores or threads.
gistlibby LogSnag