Node native decrypter for EJSON
npm install node-ejsonNode.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
`javascript
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:
`javascript`
{
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
0.3.2 2025-06-25
- Fix nested configs.
0.3.1 2025-06-17
- Fix config reading bug.
0.3.0 2025-06-08
- Allow passing parsed JSON. No need for file system read and works in more cloud environments.
- Include common configs
- Allow local overrides