- 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 ORDER BY 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL JOIN 連線
- 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 - url.username 屬性
URL 類 的 **NodeJS url.username 屬性** 用於獲取和設定提供的 URL 的使用者名稱。如果無效的 URL 字元出現在分配給 username 屬性的值中,則它們將被百分比編碼。百分比編碼字元的選擇可能與 url.parse() 和 url.format() 方法產生的結果略有不同。
Node.js URL 模組提供了多個用於 URL 解析和解析的實用程式。
語法
以下是 **URL 類 的 NodeJS username 屬性** 的語法
URL.username
引數
此方法不接受任何引數。
返回值
此屬性獲取並設定 URL 的使用者名稱部分。
示例
如果我們將完整的 URL 分配給 NodeJS url.username 屬性,它將獲取 URL 的使用者名稱部分。
在以下示例中,我們嘗試獲取提供的 URL 的使用者名稱段。
const http = require('url');
const myURL = new URL('https://Nikhil:hyd@tutorialspoint.com');
console.log("Username portion of the URL is: " + myURL.username);
輸出
執行上述程式後,username 屬性從提供的 URL 獲取使用者名稱段。
Username portion of the URL is: Nikhil
示例
username 屬性允許將有效值設定為給定 URL 中的使用者名稱段。
在下面的程式中,我們嘗試將值設定為輸入 URL 中的使用者名稱段。
const http = require('url');
const myURL = new URL('https://Nikhil:hyd@tutorialspoint.com');
console.log("The URL: " + myURL.href);
console.log("Username portion of the URL is: " + myURL.username);
myURL.username = "Nikhilesh";
console.log("Trying to change the username to - " + myURL.username);
console.log("The URL after modifying: " + myURL.href);
輸出
正如我們在下面的輸出中看到的,輸入 URL 的使用者名稱段已修改。
The URL: https://Nikhil:hyd@tutorialspoint.com/ Username portion of the URL is: Nikhil Trying to change the username to - Nikhilesh The URL after modifying: https://Nikhilesh:hyd@tutorialspoint.com/
示例
如果在 URL 的使用者名稱部分出現任何無效的 URL 字元,則這些字元將被百分比編碼。
在以下示例中,我們分配了一個在使用者名稱部分包含無效字元的 URL。
const http = require('url');
const myURL = new URL('https://Ni`khi`l:hyd@tutorialspoint.com');
console.log("The URL: " + myURL.href);
console.log("Username portion of the URL is: " + myURL.username);
輸出
正如我們在輸出中看到的,URL 中的無效字元已進行百分比編碼。
The URL: https://Ni%60khi%60l:hyd@tutorialspoint.com/ Username portion of the URL is: Ni%60khi%60l
nodejs_url_module.htm
廣告
