Drop-Nodejs16
Drop-Nodejs16 copied to clipboard
Drop Node.js 16 support
Drop Node.js 16 support in your projects
- Now: October 2023, we have Node.js 18.18.0 LTS and 20.7.0 (current)
- Going to drop Node.js 16 support before its end-of-file 2023-09-11 in Metarhia codebase, all projects, and course examples
- Now we can rely on Node.js 18.18.0 capabilities
- See release schedule: github.com/nodejs/release#release-schedule
Important notes
- Before this one see also previous checklist "Drop Node.js 14": github.com/tshemsedinov/Drop-Nodejs14
- New node.js uses
OpenSSL 3instead ofOpenSSL 1.1.1. This led to an early end of support for Node.js 16 LST: September 11th, 2023. See details: nodejs.org/en/blog/announcements/nodejs16-eol
Refactoring checklist as of October 2023
- Due to the move from
npm v9or later version, convertpackage_lock.jsontolockfileVersion 3by command:npm i --lockfile-version 3 - Run your project with flag
--pending-deprecationto see deprecation warnings and then with flag--throw-deprecationto exit with non-zero on deprecated API calls - Use native Fetch API instead of polyfill like
undiciornode-fetch. Now you can avoidaxiosandrequest()fromnode:http - You can use Web Streams API to be compatible with browser API in server-side rendering or so
- Use
Buffermethod.subarray(start, end)instead of deprecated.slice(start, end): see Buffer docs - Stop using deprecated
url.parse: see DEP0169 docs - Stop using deprecated
Thenablein streams: see DEP0157 docs - Use http events:
dropRequestanddrop: see http docs - Use
server.closeAllConnections()andserver.closeIdleConnections(): see http docs - Use
module.isBuiltin(moduleName): see module docs - Now we can use new
V8features: - Use promise-based
node:readlineAPI, example:const name = await rl.question('Name:');and new methods:clearLine,commitandrollback,cursorTo,moveCursor, classInterface - Do not use
node:async_hooksAPI likecreateHookandAsyncHookas non-stable, except stable classesAsyncLocalStorageandAsyncResource, see docs in a separate article "async context tracking"
Explore new features
- Stable Web Crypto API (
globalThis.cryptoorrequire('node:crypto').webcrypto) - Improvements to the Intl API
- Class
Blobfromnode:buffer - Class
BrodcastChannelfromnode:worker_threads - Global function
structuredClone - Class
v8.GCProfiler - Now
child_process.forksupportsfile:protocol
Note that you can't freely use
- Now we have native test runner module:
node:testbut it is not completely ready in all aspects. By the waynode:testis a first module available just withnode:prefix, it means: you can't access it byrequire('test') - Single executable applications
- Both experimental module-based and process-based permission model
- Experimental
--watchflag to enable auto-restart on changes - Experimental Web Streams API
- Experimental method subprocess[Symbol.dispose] added in node.js 20.5.0 to send
SIGTERMto spawned child process - Experimental class
File - Experimental classes
TracingChannel,CustomEvent,CompressionStream,CustomEvent
Use node.js features instead of dependencies
- Use native Fetch API instead of npm modules
undici,request,axios,node-fetch - See previous recommendations for removing third-party dependencies in favour of node.js internal modules
Related links
- See 100 NodeJS Interview Questions
- See Node.js 2023 course index
- See free Node.js lectures index