Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vandium-io/env-restorer
Environment variable restorer
https://github.com/vandium-io/env-restorer
Last synced: 3 days ago
JSON representation
Environment variable restorer
- Host: GitHub
- URL: https://github.com/vandium-io/env-restorer
- Owner: vandium-io
- License: bsd-3-clause
- Created: 2016-05-15T21:20:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-15T21:27:00.000Z (over 8 years ago)
- Last Synced: 2024-12-07T21:19:58.307Z (about 1 month ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/vandium-io/env-restorer.svg?branch=master)](https://travis-ci.org/vandium-io/env-restorer)
[![npm version](https://badge.fury.io/js/env-restorer.svg)](https://badge.fury.io/js/env-restorer)# env-restorer
Utility that snapshots the environment variables from `process.env` and can restore
them on demand. Initially developed for testing [vandium](https://github.com/vandium-io/vandium-node/).## 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.
```js
const envRestorer = require( 'env-restorer' );// change environment variables
process.env.MY_SPECIAL_VALUE = '42';envRestorer.restore();
// 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()`:
```js
const envRestorer = require( 'env-restorer' );// change environment variables
process.env.MY_SPECIAL_VALUE = '42';const snapshot = envRestorer.snapshot();
// change environment variables
process.env.MY_SPECIAL_VALUE = '43';snapshot.restore();
// process.env.MY_SPECIAL_VALUE will now equal '42'envRestorer.restore();
// 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 `[email protected]`
## License
[BSD-3-Clause](https://en.wikipedia.org/wiki/BSD_licenses)