/Drop-Nodejs14

Drop Node.js 14 support

MIT LicenseMIT

Drop Node.js 14 support in your projects

  • Now: April 2023, we have Node.js 18.16.0 LTS, 16.20.0 (maintenance) and 20.0.0 (latest)
  • Going to drop Node.js 14 support in all HowProgrammingWorks and Node.js courses, Metarhia codebase
  • Now we can rely on Node.js 16.20.0 capabilities
  • See release schedule: https://github.com/nodejs/release#release-schedule

Refactoring checklist as of April 2023

  • Due to the move from npm 6 to npm 8, convert package_lock.json to lockfileVersion 2
  • Now we can use true #privateField syntax instead of _pseudoPrivateField or closures for "Information Hiding" principle
  • Change deprecated cluster.isMaster to cluster.isPrimary, change cluster.setupMaster to cluster.setupPrimary
  • Check all require calls to use node: prefix for all internal node.js modules, for example: node:fs
  • Use crypto.randomUUID() to generate UUID instead of manual generation or third-party modules
  • Stop using fs.exists; use fs.stat or fs.access instead
  • Stop using fs.rmdir(path, { recursive: true }); use fs.rm(path, { recursive: true }) instead, see docs: https://nodejs.org/api/fs.html#fsrmpath-options-callback
  • Check stream.destroyed instead of the .aborted property, and listen for close event instead of abort and aborted events for ClientRequest, ServerResponse, and IncomingMessage
  • Stop using deprecated Server.connections; use Server.getConnections() instead, see docs: https://nodejs.org/api/net.html#servergetconnectionscallback
  • Do not use default index.js as of Node.js 16.0.0; the main entry point should be explicitly defined
  • Stop using emitter.listeners; use events.getEventListeners(emitter, eventName) instead, see docs: https://nodejs.org/api/events.html#eventsgeteventlistenersemitterortarget-eventname
  • Now response (http.ServerResponse) has a reference to request instance (http.IncomingMessage): response.req
  • Stop using node:url API; use JavaScript URL class instead
  • Note that unhandled promise rejections are deprecated and will terminate the process with a non-zero exit code. Add a process.on('uncaughtException', (reason, origin) => {}) handler to prevent process termination
  • Stop using deprecated process.on('multipleResolves', handler)
  • Stop using deprecated process.config
  • Check for deprecated Thenable support in streams
  • Ensure only integer values are used for process.exit(code) and process.exitCode
  • The well-known MODP groups modp1, modp2, and modp5 are deprecated due to their lack of security against practical attacks
  • Use http.createServer({ noDelay, keepAlive, keepAliveInitialDelay }), no need in request.setNoDelay anymore
  • New os.machine() returns one of machine types as a string: arm, arm64, aarch64, mips, mips64, ppc64, ppc64le, s390, s390x, i386, i686, x86_64

Explore new features

Available in all currently supported Node.js versions as of April 2023

Note that you can't freely use

  • Following features are still experimental in at least one of supported node.js versions --watch, process.getActiveResourcesInfo, fs.cp, and fsPromises.cp, Readable methods map, filter, compose, iterator, forEach and so on
  • ESM and CJS loaders API is currently being redesigned and will still change
  • Startup Snapshot API and Web Streams API are still experimental, see docs: https://nodejs.org/api/v8.html#startup-snapshot-api