
- 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
廣告