1、在nodejs中不能使用浏览器的API

常见的浏览器的API有哪些?
DOM 操作:document、getElementById、createElement、appendChild 等
DOM 事件:addEventListener
BOM 操作:window、navigation、sreen
XMLHTTPRequest,但 fetch 是可以在 Nodejs中使用的。
2、nodejs 内置的 API
nodejs是作为一个软件安装在操作系统上的,所以nodejs提供了操作系统的 API。
javascript
const os = require('os') //和import语法类似
function getSystemInfo(){
return {
platform: os.platform(),
type: os.type(),
architecture: os.arch(),
cpuCount: os.cpus().length,
cpuModel: os.cpus()[0].model,
totalMemoryGB: Math.round(os.totalmem() / 1024 / 1024 / 1024),
hostname: os.hostname()
}
}
const systemInfo = getSystemInfo()
console.log(systemInfo)
运行结果:
