- Node.js 教程
- Node.js - 首页
- Node.js - 简介
- Node.js - 环境搭建
- Node.js - 第一个应用程序
- Node.js - REPL 终端
- Node.js - 命令行选项
- Node.js - 包管理器 (NPM)
- Node.js - 回调函数概念
- Node.js - 上传文件
- Node.js - 发送电子邮件
- Node.js - 事件
- Node.js - 事件循环
- Node.js - 事件发射器
- Node.js - 调试器
- Node.js - 全局对象
- Node.js - 控制台
- Node.js - 进程
- Node.js - 应用程序扩展
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTFul API
- Node.js - 缓冲区
- Node.js - 流
- Node.js - 文件系统
- Node.js MySQL
- Node.js - MySQL 入门
- Node.js - MySQL 创建数据库
- Node.js - MySQL 创建表
- Node.js - MySQL 插入数据
- Node.js - MySQL 从表中选择数据
- Node.js - MySQL Where 条件
- Node.js - MySQL 排序
- Node.js - MySQL 删除数据
- Node.js - MySQL 更新数据
- Node.js - MySQL 联接
- Node.js MongoDB
- Node.js - MongoDB 入门
- Node.js - MongoDB 创建数据库
- Node.js - MongoDB 创建集合
- Node.js - MongoDB 插入数据
- Node.js - MongoDB 查找数据
- Node.js - MongoDB 查询
- Node.js - MongoDB 排序
- Node.js - MongoDB 删除数据
- Node.js - MongoDB 更新数据
- Node.js - MongoDB 限制结果
- Node.js - MongoDB 联接
- Node.js 模块
- Node.js - 模块
- Node.js - 内置模块
- Node.js - 实用程序模块
- Node.js - Web 模块
- Node.js 有用资源
- Node.js - 快速指南
- Node.js - 有用资源
- Node.js - 讨论
Node.js - os.hostname() 方法
Node.js 的os模块提供了一系列与操作系统相关的实用程序方法和属性。
Node.js os.hostame() 方法将获取当前操作系统的主机名。这用于检索操作系统的网络名称。此方法将返回一个字符串作为输出。返回的值也可能因操作系统的设置和配置而异。
语法
以下是Node.js os.hostname()方法的语法:
os.hostname()
参数
此方法不接受任何参数。
返回值
此方法将返回当前操作系统的宿主机的名称,作为一个字符串。
示例
在下面的示例中,我们首先导入了os模块。然后我们尝试使用os.hostname()方法打印当前操作系统的主机名。
const os = require('os');
console.log(os.hostname());
输出
82a25c5e95a1
注意 - 为了获得准确的结果,最好在本地执行上述代码。
如果我们编译并运行上述程序,os.hostname()方法将返回当前操作系统的 hostname。
Nikhilesh
示例
以下是另一个获取当前操作系统主机名的示例。
const os = require('os');
var name_of_the_host = os.hostname();
do{
console.log('The Hostname of this current computer is: ' + name_of_the_host);
break;
}
while (os.hostname());
输出
The Hostname of this current computer is: 82a25c5e95a1
注意 - 为了获得准确的结果,最好在本地执行上述代码。
执行上述程序后,os.hostname()方法将当前操作系统的 hostname 打印到控制台。
The Hostname of this current computer is: Nikhilesh
nodejs_os_module.htm
广告
