Paul Krill
Editor at Large

Node.js adds built-in API for on-disk caching

news
Sep 11, 20242 mins

The latest JavaScript runtime update also supports requiring code coverage thresholds are met before a process can exit.

IDC
Credit: Aon Khanisorn

Node.js 22.8.0, the latest release of the event-driven JavaScript runtime, adds a JavaScript API to enable on-disk caching of all modules loaded after the API is called, presenting a caching option for code.

The API is called module.enable.CompileCache(). It overrides the NODE_COMPILE_CACHE environment variable, which only end users could use to enable on-disk caching. The new API lets tool and library authors manage the caching of their own code. The solution is a built-in alternative to v8-compile-cache packages, offering better performance and support for ESM (ECMAScript Modules).

Introduced on September 3, Node 22.8.0 can be downloaded from Nodejs.org. It is classified as a current release rather than an LTS (long-term support) release. With this update, Node now supports requiring code coverage to meet a specific threshold before a process successfully exits. Developers who want to use this capability must set the –experimental-test-coverage flag. Thresholds can be set for types of coverage including branch, function, and line coverages. Also in version 22.8.0, a flavor of vm.createContext() has been added to create a context without contextifying its global object when vm.constants.DONT_CONTEXTIFY is used. This is suitable when users want to freeze the context or speed up global access if they do not need the interceptor behavior.

Node 22.8.0 follows the August 22 release of Node 22.7.0, which featured experimental transform types support. Node 22 itself was announced April 24, emphasizing ESM and an improved WebSocket client.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author