
- 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 條件查詢
- 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 - 討論
NodeJS - urlObject.auth 屬性
URL 字串是一個包含多個片段的結構化字串。如果我們解析這個 URL 字串,則會返回一個 URL 物件。返回的 URL 物件包含 URL 字串中存在的片段。
NodeJS urlObject.auth 屬性 指定 URL 的 auth 片段。它也稱為使用者資訊。URL 中 auth 片段的格式為 {username}[:{password}]。
沒有規定 auth 片段的格式必須相同,[:{password}] 部分是可選的。
語法
以下是NodeJS urlObject.auth 屬性的語法
urlObject.auth
引數
此屬性不接受任何引數。
返回值
此屬性檢索 URL 的使用者名稱和密碼片段。
示例
如果提供的 URL 包含 auth 片段,即 {username}[:{password}] 格式,則 auth 屬性將檢索該片段。
在下面的示例中,我們嘗試從提供的 URL 獲取 auth 片段。
注意:要使用 auth 屬性從 URL 獲取 auth 片段,我們首先需要使用 NodeJS url.parse() 方法解析 URL;否則 auth 片段未定義。
const url = require('url'); let address = 'https://username=Nikhil:password=TutPoint@www.Tutorialspoint.com#foo'; let result = url.parse(address, true); console.log(result.auth);
輸出
正如我們在下面的輸出中看到的,NodeJS auth 屬性從 URL 中檢索了 auth 片段。
username=Nikhil:password=TutPoint
示例
如果我們不解析指定的 URL,則 auth 屬性將未定義。
我們嘗試從提供的 URL 獲取 auth 片段而不進行解析。
const url = require('url'); let address = 'https://username=Nikhil:password=TutPoint@www.Tutorialspoint.com#foo'; console.log(address.auth);
輸出
正如我們在下面的輸出中看到的,auth 屬性未定義。
undefined
示例
auth 片段中的[:{password}]部分是可選的。
在下面的示例中,提供的 URL 只包含使用者名稱。
const url = require('url'); let address = 'https://username=Nikhil@www.Tutorialspoint.com#foo'; let result = url.parse(address, true); console.log(result.auth);
輸出
以下是上述程式碼的輸出
username=Nikhil
示例
如果提供的 URL 不包含 auth 片段,則 auth 屬性將檢索 null。
const url = require('url'); let address = 'https:www.Tutorialspoint.com'; let result = url.parse(address, true); console.log(result.auth);
輸出
正如我們在下面的輸出中看到的,auth 屬性為 null,因為 URL 中不包含 auth 片段。
null
nodejs_url_module.htm
廣告