crypto.createCredentials usage to the modern tls.createSecureContext API for managing TLS credentials.
What It Does
The codemod transforms:- Imports from
node:crypto→node:tls createCredentialsfunction →createSecureContext- All function calls to use the new API
Usage
Examples
- CommonJS
- ESM
Before
After
Options
ThecreateSecureContext function accepts the same options as the deprecated createCredentials:
key- Private key in PEM formatcert- Certificate chain in PEM formatca- Array of trusted CA certificatespfx- PFX or PKCS12 encoded private key and certificate chainpassphrase- Passphrase for the private key or pfxciphers- Cipher suite specificationhonorCipherOrder- Use server’s cipher preferencessecureProtocol- SSL method to use- And more - see Node.js TLS documentation
Why Migrate?
Migrating totls.createSecureContext:
- Uses the correct module (
tlsinstead ofcrypto) - Aligns with Node.js best practices
- Provides better semantic clarity about the function’s purpose
- Ensures compatibility with future Node.js versions