博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node.js 的 os 模块
阅读量:7280 次
发布时间:2019-06-30

本文共 1951 字,大约阅读时间需要 6 分钟。

 

  Node.js的os module 提供了一系列跟操作系统相关的操作函数,比较简单,所以功能也就十分有限。我们可以去官网看各个函数的介绍:

  http://nodejs.org/api/os.html 

2 var os = require('os'); 3  4 console.log('the os tmpdir is: ' + os.tmpdir()); 5 console.log('the endianness of this os is: ' + os.endianness()); 6 console.log('the hostname of this os is: ' + os.hostname()); 7 console.log('the type of this os is: ' + os.type()); 8 console.log('the platform of this os is: ' + os.platform()); 9 console.log('the arch of this os is: ' + os.arch());10 console.log('the release of the os is: ' + os.release());11 console.log('the uptime os the os is: ' + os.uptime());12 13 14 console.log('the end of line of this os is: ' + os.EOL);  //os.EOL:操作系统的换行符15 console.log('................................................');16 console.log('................................................');17 showObj(os.cpus());18 console.log('................................................');19 console.log('................................................');20 showObj(os.networkInterfaces());21 console.log('................................................');22 console.log('................................................');23 showObj(os.loadavg());24 25 26 27 28 function showObj(obj){29     if (obj == null) {30         console.log('error: ' + obj);    31         return false;32     }33     for (var key in obj)    {34         //key is a string, so we cannot use obj.key to replace obj[key] at here. For example, if name is a property of obj:       //(obj.name is right, but obj."name" is wrong.)       //(obj["name"] is right, but obj[name] is wrong.) 35         if (typeof(obj[key]) == 'array' || typeof(obj[key]) == 'object') {36             showObj(obj[key]);    37         } else {38             if (obj[key] != null)39                 console.log(key + "=" + obj[key]);    40         }41     }42 }43

参考博客地址:http://blog.csdn.net/simpleiseasy/article/details/7253429 

转载于:https://www.cnblogs.com/chenchenluo/p/4227993.html

你可能感兴趣的文章
堡垒机搭建有哪些注意事项?
查看>>
检测内存的使用率
查看>>
Android studio 新建 模拟器HAX kernel moudle is not inst
查看>>
虚拟,混合和SD-WAN如何比较和对比
查看>>
Zookeeper架构及FastLeaderElection机制
查看>>
tomcat安装配置
查看>>
push-消息推送
查看>>
Hierarchical or taxonomy data filter
查看>>
PHP写入TXT文件函数
查看>>
虚拟机创建GentOS 64以及安装的操作步骤
查看>>
Failed to execute goal on project dubboxdemo-servi
查看>>
成为一名Java架构师的必修课
查看>>
年薪50W+的网络安全人才需要具备哪些条件?
查看>>
php短信接口,免认证限制少的接口,手机短信,短信验证码
查看>>
linux 命令
查看>>
Go Timer实现原理剖析(轻松掌握Timer实现原理)
查看>>
django 内置标签和过滤器
查看>>
mysql主从复制
查看>>
C++多态的概念
查看>>
关于中文乱码问题的一些解决方案和经验
查看>>