• Returns: {Buffer}

    Creates a code cache that can be used with the SourceTextModule constructor’s cachedData option. Returns a Buffer. This method may be called any number of times before the module has been evaluated.

    1. // Create an initial module
    2. const module = new vm.SourceTextModule('const a = 1;');
    3. // Create cached data from this module
    4. const cachedData = module.createCachedData();
    5. // Create a new module using the cached data. The code must be the same.
    6. const module2 = new vm.SourceTextModule('const a = 1;', { cachedData });