恕我直言,最好的选择是使用系统信息模块,
通过 Linux、macOS、部分 Windows 和 FreeBSD 支持,您可以在其中检索详细的硬件、系统和操作系统信息。
例如获取 CPU 信息:
const si = require('systeminformation');
// callback style
si.cpu(function(data) {
console.log('CPU-Information:');
console.log(data);
});
// promises style - new in version 3
si.cpu()
.then(data => console.log(data))
.catch(error => console.error(error));
// full async / await example (node >= 7.6)
async function cpu() {
try {
const data = await si.cpu();
console.log(data)
} catch (e) {
console.log(e)
}
}
此示例将产生以下结果:
{ manufacturer: 'Intel®',
brand: 'Core™ i5-3317U',
vendor: 'GenuineIntel',
family: '6',
model: '58',
stepping: '9',
revision: '',
voltage: '',
speed: '1.70',
speedmin: '0.80',
speedmax: '2.60',
cores: 4,
cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 3145728 } }
CPU-Information:
{ manufacturer: 'Intel®',
brand: 'Core™ i5-3317U',
vendor: 'GenuineIntel',
family: '6',
model: '58',
stepping: '9',
revision: '',
voltage: '',
speed: '1.70',
speedmin: '0.80',
speedmax: '2.60',
cores: 4,
cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 3145728 } }