Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
Published By From Node.js News · 1 min read
CodeNode.js v20 to v22
This article covers a part of the migration from Node.js v20 to v22. The userland migrations team is working on more codemods to help you with the migration.
This page provides a list of codemods to help you migrate your code from Node.js v20 to v22.
During the process of TC39 standardization, the import assert feature was introduced to allow importing JSON modules , but during the transition to stage 4, the assert keyword was replaced with the with attribute on the import statement.
So in node.js v22 , the import assert feature was removed and the with attribute is required instead.
Also note that the with keyword was introduced in node.js v18.20 but it was not mandatory until v22.
This is an excerpt. The full article is published by Node.js News.
Answers to common questions regarding this article's topic, architecture, and practical applications.
Replaces invocations of createCipher() / createDecipher() with createCipheriv() / createDecipheriv() . Inserts scaffolding that derives keys with crypto.scryptSync() and generates random salts and IVs. Reminds developers to persist salt + IV for decryption and to adjust key/IV lengths per algorithm. Updates destructured imports to include the new helpers ( createCipheriv , createDecipheriv , randomBytes , scryptSync ). Example</
General
This article covers a part of the migration from Node.js v20 to v22. The userland migrations team is working on more codemods to help you with the migration.
Definition / Understanding
During the process of TC39 standardization, the import assert feature was introduced to allow importing JSON modules, but during the transition to stage 4, the assert keyword was replaced with the with attribute on the import statement. So in node.js v22, the import assert feature was removed and the with attribute is required instead. Also note that the with keyword was introduced in node.js v18.20 but it was not mandatory until v22. The source
General
- const cipher = crypto.createCipher(algorithm, password); + const cipher = (() => { + const __dep0106Salt = crypto.randomBytes(16); + const __dep0106Key = crypto.scryptSync(password, __dep0106Salt, 32); + const __dep0106Iv = crypto.randomBytes(16); + // DEP0106: Persist __dep0106Salt and __dep0106Iv alongside the ciphertext so it can be decrypted later. + return crypto.createCipheriv(algorithm, __dep0106Key, __dep0106Iv); + })(); Diff Important
General
The codemod cannot guarantee algorithm-specific key/IV sizes. Review the generated scryptSync length and IV length defaults and adjust as needed. Decryption snippets include placeholders ( Buffer.alloc(16) ) that must be replaced with the salt and IV stored during encryption. If your project already wraps key derivation logic, you may prefer to adapt the generated scaffolding to call existing helpers. The generated code is not backward-compatible