env-restorer
Utility that snapshots the environment variables from process.env
and can restore
them on demand. Initially developed for testing vandium.
Features
- Automatically snapshots environment variable state
- Nested snapshots are allowed
- No dependencies
Installation
Install via npm.
npm install env-restorer
Getting Started
A snapshot of the environment variables is created automatically when the library is loaded.
const envRestorer = ; // change environment variablesprocessenvMY_SPECIAL_VALUE = '42'; envRestorer;// restore environment variables back to initial state (MY_SPECIAL_VALUE will no longer exist)
To create another snapshot of the environment variables state, simply call snapshot()
:
const envRestorer = ; // change environment variablesprocessenvMY_SPECIAL_VALUE = '42'; const snapshot = envRestorer; // change environment variablesprocessenvMY_SPECIAL_VALUE = '43'; snapshot;// process.env.MY_SPECIAL_VALUE will now equal '42' envRestorer;// restore environment variables back to initial state (MY_SPECIAL_VALUE will no longer exist)
Feedback
We'd love to get feedback on how to make this tool better. Feel free to contact us at feedback@vandium.io