https://github.com/faradayio/vault-env-js
Put your vault secrets in your process.env
https://github.com/faradayio/vault-env-js
Last synced: 8 months ago
JSON representation
Put your vault secrets in your process.env
- Host: GitHub
- URL: https://github.com/faradayio/vault-env-js
- Owner: faradayio
- License: mit
- Created: 2016-03-08T00:31:10.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-04-17T17:22:16.000Z (about 1 year ago)
- Last Synced: 2025-04-18T06:59:11.732Z (about 1 year ago)
- Language: TypeScript
- Size: 174 KB
- Stars: 10
- Watchers: 5
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vault-env-js
Put your [vault](https://www.vaultproject.io/) secrets in your [process.env](https://nodejs.org/api/process.html#process_process_env)

Install the package
```console
npm install --save vault-env
```
Write a `Secretfile` in your app directory
```txt
DATABASE_URL secrets/databases/main:url
```
Require `vault-env` and the environment variables are loaded
```js
require("vault-env");
console.log(process.env.DATABASE_URL);
// => 'postgres://...'
```
Provide your app with `VAULT_ADDR` and `VAULT_TOKEN` environment variables when
you run it.
```console
VAULT_ADDR=https://localhost:8200 VAULT_TOKEN=12345 node ./app.js
```
Require `vault-env/rotate` and vault-env will request new leases before your
secrets expire, keeping your environment variables up to date forever.
```js
require("vault-env/rotate");
// check the database url
console.log(process.env.DATABASE_URL);
// => 'postgres://username:password@host/db'
// check again in six weeks
setTimeout(function () {
console.log(process.env.DATABASE_URL);
// => 'postgres://user:newpassword@host/db'
}, 1000 * 60 * 60 * 24 * 7 * 6);
```
Watch for secret changes
```js
var vaultEnv = require("vault-env/rotate");
vaultEnv.on("DATABASE_URL", function (newDB, oldDB) {
console.log("DATABASE_URL has changed to " + newDB + " from " + oldDB);
});
```
Require `vault-env/local` and vault-env will not set your environment
your variables will only be exported by the module as regular variables
```js
var secret = require("vault-env/local");
console.log(secret.DATABASE_URL);
// => 'postgres://...'
```