| date | 2025-10-28T00:01:00.000Z |
|---|---|
| category | migrations |
| title | Node.js v14 to v16 |
| layout | blog-post |
| author | AugustinMauroy |
This page provides a list of codemods to help you migrate your code from Node.js v14 to v16.
Node.js v16 replaced the createRequireFromPath function, deprecated in DEP0148, with the modern createRequire function. This codemod replaces calls of the deprecated function with the modern alternative mentioned.
The source code for this codemod can be found in the create-require-from-path directory.
You can find this codemod in the Codemod Registry.
npx codemod run @nodejs/create-require-from-pathimport { createRequireFromPath } from 'node:module';
const requireFromPath = createRequireFromPath('/path/to/module');
const myModule = requireFromPath('./myModule.cjs');import { createRequire } from 'node:module';
const require = createRequire('/path/to/module');
const myModule = require('./myModule.cjs');The process.mainModule property was deprecated in favor of require.main. This codemod will help you replace the old process.mainModule usage with the new require.main usage.
So the codemod handle DEP0138.
The source code for this codemod can be found in the process-main-module directory.
You can find this codemod in the Codemod Registry.
npx codemod run @nodejs/process-main-moduleif (process.mainModule === 'mod.js') {
// cli thing
} else {
// module thing
}if (require.main === 'mod.js') {
// cli thing
} else {
// module thing
}The process.mainModule property was deprecated (DEP0144) in favor of require.main. This codemod replaces calls of the deprecated property with the modern alternative mentioned.
The source code for this codemod can be found in the process-mainModule-to-require-main directory.
You can find this codemod in the Codemod Registry.
npx codemod run @nodejs/process-mainModule-to-require-mainif (process.mainModule) {
console.log('This script is the main module');
}if (require.main === module) {
console.log('This script is the main module');
}The fs.rmdir function was deprecated in favor of fs.rm with the { recursive: true } option. This codemod will help you replace the old fs.rmdir function with the new fs.rm function.
so this codemod handle DEP0147.
The source code for this codemod can be found in the rmdir directory.
You can find this codemod in the Codemod Registry.
npx codemod run @nodejs/rmdir// Using fs.rmdir with the recursive option
fs.rmdir(path, { recursive: true }, callback);
// Using fs.rmdirSync with the recursive option
fs.rmdirSync(path, { recursive: true });
// Using fs.promises.rmdir with the recursive option
fs.promises.rmdir(path, { recursive: true });// Using fs.rm with recursive and force options
fs.rm(path, { recursive: true, force: true }, callback);
// Using fs.rmSync with recursive and force options
fs.rmSync(path, { recursive: true, force: true });
// Using fs.promises.rm with recursive and force options
fs.promises.rm(path, { recursive: true, force: true });The tmpDir function was renamed to tmpdir in Node.js v16. This codemod will help you replace all instances of tmpDir with tmpdir.
So the codemod handles DEP0022.
The source code for this codemod can be found in the tmpdir-to-tmpdir directory.
You can find this codemod in the Codemod Registry.
npx codemod run @nodejs/tmpDir-to-tmpdirimport { tmpDir } from 'node:os';
const foo = tmpDir();import { tmpdir } from 'node:os';
const foo = tmpdir();