Node.js native decrypter for EJSON (Encrypted JSON)
node-ejson is a lightweight Node.js library for working with EJSON (Encrypted JSON) files. It provides functionality to decrypt EJSON-encrypted values, making it easy to manage sensitive configuration data in your Node.js applications.
npm install node-ejson
import processEjson from 'node-ejson';
const config = await processEjson();
console.log(config.decrypted_secret);
- Decrypt EJSON-encrypted values
- Support for custom configuration options
- Environment variable support
- Nested object decryption
node-ejson uses the following default configuration:
{
envFilePath: process.env.NODE_EJSON_FILE_PATH ?? undefined,
envFileDir: '.',
envFilePrefix: process.env.NODE_ENV ?? 'env',
envFileSuffix: '.ejson',
keysDir: '/opt/ejson/keys/',
getPrivateKey: async (publicKey, conf) => {
if (process.env.NODE_EJSON_PRIVATE_KEY) {
return process.env.NODE_EJSON_PRIVATE_KEY;
} else {
return await fs.readFile(conf.keysDir + publicKey, 'utf8');
}
}
}
You can override these settings by passing a configuration object to processEjson()
.
NODE_EJSON_FILE_PATH
: Custom path to the EJSON fileNODE_ENV
: Used as the prefix for the EJSON file name (default: 'env')NODE_EJSON_PRIVATE_KEY
: Private key for decryption (optional)
Run the test suite with:
npm test
MIT
- Include common configs
- Allow local overrides