欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Node.js19有哪些特性

今天小編給大家分享一下Node.js19有哪些特性的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

創(chuàng)新互聯(lián)是一家專業(yè)從事成都網站設計、網站制作的網絡公司。作為專業(yè)的建站公司,創(chuàng)新互聯(lián)依托的技術實力、以及多年的網站運營經驗,為您提供專業(yè)的成都網站建設、全網整合營銷推廣及網站設計開發(fā)服務!

Node.js 14 將在 2023 年 4 月結束更新維護,Node.js 16 (LTS) 預計將在 2023 年 9 月結束更新維護。

而Node 19 在 2022-10-18 發(fā)布。

我們知道 Node.js 版本分兩種:LTS 和 Current

Node.js19有哪些特性

其中,Current 版本通常每 6 個月發(fā)布一次。

每年 4 月份發(fā)布新的偶數版本;

每年 10 月份發(fā)布新的奇數版本;

在剛過去的 10 月,發(fā)布的 V19.0.1 成為最新的 “Current” 嘗鮮版,它一共帶來 6 大特性。

1. HTTP(S)/1.1 KeepAlive 默認為 true

Node.js v19 設置 keepAlive 默認值為 true,這意味著所有出站的 HTTP(s) 連接都將使用 HTTP 1.1 keepAlive,默認時間為 5S;

代碼測試:

const http = require('node:http');
console.log(http.globalAgent);
const https = require('node:https');
console.log(https.globalAgent);

我們可以對比看看 v16 和 v19 的 node server Agent 配置差異:

  • V16

% nvm use 16
Now using node v16.0.0 (npm v7.10.0)
% node server
Agent {
  _events: [Objectnull prototype] {
    free: [Function (anonymous)],
    newListener: [Function: maybeEnableKeylog]
  },
  _eventsCount2,
  _maxListenersundefined,
  defaultPort80,
  protocol'http:',
  options: [Objectnull prototype] { pathnull },
  requests: [Objectnull prototype] {},
  sockets: [Objectnull prototype] {},
  freeSockets: [Objectnull prototype] {},
  keepAliveMsecs1000,
  keepAlive : false,
  maxSocketsInfinity,
  maxFreeSockets256,
  scheduling'lifo',
  maxTotalSocketsInfinity,
  totalSocketCount0,
  [Symbol(kCapture)]: false
}
Agent {
  _events: [Objectnull prototype] {
    free: [Function (anonymous)],
    newListener: [Function: maybeEnableKeylog]
  },
  _eventsCount2,
  _maxListenersundefined,
  defaultPort443,
  protocol'https:',
  options: [Objectnull prototype] { pathnull },
  requests: [Objectnull prototype] {},
  sockets: [Objectnull prototype] {},
  freeSockets: [Objectnull prototype] {},
  keepAliveMsecs1000,
  keepAlivefalse,
  maxSocketsInfinity,
  maxFreeSockets256,
  scheduling'lifo',
  maxTotalSocketsInfinity,
  totalSocketCount0,
  maxCachedSessions100,
  _sessionCache: { map: {}, list: [] },
  [Symbol(kCapture)]: false
}

第 18、40 行,keepAlive 默認設置為 false;

  • V19

% nvm use 19
Now using node v19.0.0 (npm v8.19.2)
% node server
Agent {
  _events: [Objectnull prototype] {
    free: [Function (anonymous)],
    newListener: [Function: maybeEnableKeylog]
  },
  _eventsCount2,
  _maxListenersundefined,
  defaultPort80,
  protocol'http:',
  options: [Objectnull prototype] {
    keepAlivetrue,
    scheduling'lifo',
    timeout5000,
    noDelaytrue,
    pathnull
  },
  requests: [Objectnull prototype] {},
  sockets: [Objectnull prototype] {},
  freeSockets: [Objectnull prototype] {},
  keepAliveMsecs1000,
  keepAlivetrue,
  maxSocketsInfinity,
  maxFreeSockets256,
  scheduling'lifo',
  maxTotalSocketsInfinity,
  totalSocketCount0,
  [Symbol(kCapture)]: false
}
Agent {
  _events: [Objectnull prototype] {
    free: [Function (anonymous)],
    newListener: [Function: maybeEnableKeylog]
  },
  _eventsCount2,
  _maxListenersundefined,
  defaultPort443,
  protocol'https:',
  options: [Objectnull prototype] {
    keepAlivetrue,
    scheduling'lifo',
    timeout5000,
    noDelaytrue,
    pathnull
  },
  requests: [Objectnull prototype] {},
  sockets: [Objectnull prototype] {},
  freeSockets: [Objectnull prototype] {},
  keepAliveMsecs1000,
  keepAlivetrue,
  maxSocketsInfinity,
  maxFreeSockets256,
  scheduling'lifo',
  maxTotalSocketsInfinity,
  totalSocketCount0,
  maxCachedSessions100,
  _sessionCache: { map: {}, list: [] },
  [Symbol(kCapture)]: false
}

第 14、16、42、44 行設置 keepAlive 默認值及時間;

啟用 keepAlive 能使連接重用,提高網絡的吞吐量。

另外,服務器將在調用 close() 自動斷開空閑的客戶端,內部依靠 http(s).Server.close API 實現;

這些修改,進一步優(yōu)化了體驗和性能。

2. 穩(wěn)定的 WebCrypto API

WebCrypto API 是一個使用密碼學構建的系統(tǒng)接口,在 node.js v19 趨于穩(wěn)定(除 Ed25519、Ed448、X25519、X448 外)。

我們可以通過調用 globalThis.cryptorequire('node:crypto').webcrypto 來訪問,下面以 subtle 加密函數為例;

const { subtle } = globalThis.crypto;

(async function() {

  const key = await subtle.generateKey({
    name'HMAC',
    hash'SHA-256',
    length256
  }, true, ['sign''verify']);

  console.log('key =', key);

  const enc = new TextEncoder();
  const message = enc.encode('I love cupcakes');

  console.log('message =', message);

  const digest = await subtle.sign({
    name'HMAC'
  }, key, message);

  console.log('digest =', digest);

})();

首先生成 HMAC 密鑰,生成的密鑰可同時用于驗證消息數據完整性和真實性;

然后,對字符串 I love cupcakes 加密;

最后創(chuàng)建 消息摘要,它是一種加密散列函數;

在控制臺顯示:key 、message 、digest 信息

% node server
key = CryptoKey {
  type'secret',
  extractable: true,
  algorithm: { name: 'HMAC', length: 256, hash: [Object] },
  usages: [ 'sign''verify' ]
}
message = Uint8Array(15) [   73, 32, 108, 111, 118,  101, 32,  99, 117, 112,   99, 97, 107, 101, 115]
digest = ArrayBuffer {
  [Uint8Contents]: <30 01 7a 5c d9 e2 82 55 6b 55 90 4f 1d de 36 d7 89 dd fb fb 1a 9e a0 cc 5d d8 49 13 38 2f d1 bc>,
  byteLength: 32
}

3. 自定義 ESM resolution 調整

Node.js 已經刪除 --experimental-specifier-resolution ,其功能現在可以通過自定義加載器實現。

可以在這個庫中測試:nodejs/loaders-test: Examples demonstrating the Node.js ECMAScript Modules Loaders API

git clone https://github.com/nodejs/loaders-test.git

% cd loaders-test/commonjs-extension-resolution-loader

% yarn install

比如 loaders-test/commonjs-extension-resolution-loader/test/basic-fixtures/index.js 文件:

import { version } from 'process';

import { valueInFile } from './file';
import { valueInFolderIndex } from './folder';

console.log(valueInFile);
console.log(valueInFolderIndex);

./file 如果沒有自定義加載器,不會去查找文件的擴展名,比如 ./file.js./file.mjs

設置自定義加載器后,則可解決上述問題:

import { isBuiltin } from 'node:module';
import { dirname } from 'node:path';
import { cwd } from 'node:process';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { promisify } from 'node:util';

import resolveCallback from 'resolve/async.js';

const resolveAsync = promisify(resolveCallback);

const baseURL = pathToFileURL(cwd() + '/').href;


export async function resolve(specifier, context, next) {
  const { parentURL = baseURL } = context;

  if (isBuiltin(specifier)) {
    return next(specifier, context);
  }

  // `resolveAsync` works with paths, not URLs
  if (specifier.startsWith('file://')) {
    specifier = fileURLToPath(specifier);
  }
  const parentPath = fileURLToPath(parentURL);

  let url;
  try {
    const resolution = await resolveAsync(specifier, {
      basedirdirname(parentPath),
      // For whatever reason, --experimental-specifier-resolution=node doesn't search for .mjs extensions
      // but it does search for index.mjs files within directories
      extensions: ['.js''.json''.node''.mjs'],
    });
    url = pathToFileURL(resolution).href;
  } catch (error) {
    if (error.code === 'MODULE_NOT_FOUND') {
      // Match Node's error code
      error.code = 'ERR_MODULE_NOT_FOUND';
    }
    throw error;
  }

  return next(url, context);
}

測試命令:

% node --loader=./loader.js test/basic-fixtures/index  
(node:56149) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
hello from file.js

將不會再報錯,正常運行。

4. 移除對 DTrace/SystemTap/ETW 支持

在 Node.js v19中,移除了對 DTrace/SystemTap/ETW 的支持,主要是因為資源的優(yōu)先級問題。

數據表明很少人用到 DTrace、SystemTap 或 ETW,維護它們沒有多大的意義。

如果你想恢復使用,可提 issues => github.com/nodejs/node…

5. 升級 V8 引擎至 10.7

Node.js v19 將 V8 JavaScript 引擎更新至 V8 10.7,其中包含一個新函數 Intl.NumberFormat,用于格式化敏感數字。

Intl.NumberFormat(locales, options)

對于不同的語言,傳入不同的 locales:

const number = 123456.789;

console.log(new Intl.NumberFormat('de-DE', { style'currency'currency'EUR' }).format(number));
console.log(new Intl.NumberFormat('ja-JP', { style'currency'currency'JPY' }).format(number));
console.log(new Intl.NumberFormat('ar-SA', { style'currency'currency'EGP' }).format(number));
console.log(new Intl.NumberFormat('zh-CN', { style'currency'currency'CNY' }).format(number));

6. 試驗 Node watch 模式

運行時增加了 node --watch 選項。

在 "watch" 模式下運行,當導入的文件被改變時,會重新啟動進程。

比如:

const express = require("express");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "../build")));

app.listen(8080() =>
  console.log("Express server is running on localhost:8080")
);
% node --watch server
(node:67643) ExperimentalWarning: Watch mode is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Express server is running on localhost:8080

以上就是“Node.js19有哪些特性”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章名稱:Node.js19有哪些特性
網站網址:http://aaarwkj.com/article8/gpjeip.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網站制作手機網站建設、建站公司、外貿網站建設外貿建站、軟件開發(fā)

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都做網站
伊人久久综在合线亚洲| 国产亚洲一区二区视频| 国产男女免费完整视频| 欧美精品一区二区亚洲| 加勒比中文字幕日本道| 亚洲日本精品一区二区三区| 亚洲欧美综合一区二区三区| 久久久精品人妻免费网站| 夫妻性生活在线视频一级片| 男女裸体做爰一进一出视频| 91在线视频麻豆国产| 最新亚洲国产高清激情| 思思久久96热在精品国产| 国产成年人免费小视频| 91九色蝌蚪国产欧美亚洲| 中文字幕精品一区二区三| 日韩欧美乱码一区二区| 亚洲大片色一区在线观看| 日本高清一区二区网站| 国产女技师口爆在线观看| 国产一区av麻豆免费观看| 日本在线一区二区三区免费视频| 熟女肥臀一区二区三区| 亚洲精品国产自在现线| 亚洲国产欧美日韩国产| 国产精品一品二区三区在线观看| 日韩午夜免费一区二区蜜桃| 欧美伊人色综合久久天天| 精品国产18禁99久久久久久| 麻豆国产传媒片在线看| 婷婷国产成人久久精品激情| 黄片视频免费观看一起草| 国产女主播在线观看免费观看| 日本特黄特色高清免费大片| 美女在线免费观看av| 日本午夜专区一区二区| 国产精品欧美久久久久无| 人妻中文字幕在线一二区| 亚洲美女av一区二区三区| 日本女人体内射精视频| 人人妻人人澡人人妻|