
- 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 - 討論
NodeJS - protocol 屬性
NodeJS url.protocol 屬性是 URL 類的一個屬性,用於獲取和設定指定 URL 的協議部分。如果分配了任何無效的 URL 協議值,此屬性將忽略它們。
語法
以下是NodeJS URL 類 protocol 屬性的語法
URL.protocol
引數
此屬性不接受任何引數。
返回值
此屬性獲取並設定提供的 URL 的協議部分。
示例
如果我們將完整的 URL 分配給 NodeJS url.protocol 屬性,它將獲取給定 URL 的協議部分。
在下面的示例中,我們嘗試從輸入 URL 中獲取協議段的值。
const http = require('url'); const myURL = new URL('https://tutorialspoint.tw'); console.log("The URL: " + myURL.href); console.log("The protocol portion of the URL is: " + myURL.protocol);
輸出
執行上述程式後,protocol 屬性將從提供的 URL 中獲取協議段。
The URL: https://tutorialspoint.tw/ The protocol portion of the URL is: https:
示例
我們可以將任何有效的協議值設定為從提供的 URL 中獲取的協議段。
在下面的示例中,我們嘗試將值 (“wss”) 設定為協議段。
const http = require('url'); const myURL = new URL('https://tutorialspoint.tw'); console.log("Before updating the protocol: " + myURL.href); myURL.protocol = "wss"; console.log("Trying to update the protocol to - " + myURL.protocol); console.log("After updating the protocol portion: " + myURL.href);
輸出
從下面的輸出中可以看到,URL 的協議段已修改。
Before updating the URL: https://tutorialspoint.tw/ Trying to update the protocol to - wss: After updating the protocol portion: wss://tutorialspoint.tw/
示例
如果在協議部分提供了任何無效的協議值,protocol 屬性將忽略它們。
在下面的示例中,我們在 protocol 屬性中分配了一個帶有無效協議值的 URL。
const http = require('url'); const myURL = new URL('https://tutorialspoint.tw'); console.log("Before updating the protocol: " + myURL.href); myURL.protocol = "wswwsss"; console.log("Trying to update the protocol to - " + "wswwsss"); console.log("After updating the protocol portion: " + myURL.href);
輸出
從輸出中可以看到,協議段中的無效協議值被忽略了。
Before updating the protocol: https://tutorialspoint.tw/ Trying to update the protocol to - wswwsss After updating the protocol portion: https://tutorialspoint.tw/
nodejs_url_module.htm
廣告