Modules

module.enableCompileCache()

Enables compilation caching for the current process when supported. Active development in this baseline. Cache is an optimization, not a guarantee of faster runs; run in a disposable directory. Tested on Node.js 22.16.0. Example output (one line per entry): ["true true"].

Formal Syntax & Structure

nodejs syntaxnodejs
module.enableCompileCache([cacheDir])

Parameters & Attributes

NameTypeDescription
cacheDirstringCache directory.

Return Value

object

Status and optional directory or message.

Working Example

Example Snippetnodejs
import { enableCompileCache, constants, getCompileCacheDir } from 'node:module';import { mkdtempSync } from 'node:fs';import { join } from 'node:path';const dir = mkdtempSync(join(process.cwd(), 'node-lab-cache-'));const r = enableCompileCache(dir);console.log(r.status === constants.compileCacheStatus.ENABLED, typeof getCompileCacheDir() === 'string');
Node.js Reference