Comparing version 3.1.0 to 3.2.0
11
index.js
@@ -7,3 +7,2 @@ 'use strict' | ||
const loadNowJSON = require('./lib/load-now-json.js') | ||
const loadPkgJSON = require('./lib/load-pkg-json.js') | ||
@@ -15,3 +14,3 @@ /** | ||
// only run this if it's not running inside Now.sh | ||
if (Boolean(process.env.NOW)) return | ||
if (Boolean(process.env.NOW_REGION || process.env.NOW)) return | ||
@@ -22,9 +21,3 @@ const secrets = loadSecrets() | ||
// load environment variables from now.json | ||
const hasLoaded = loadNowJSON(secrets, required) | ||
// if now.json doesn't exists | ||
if (!hasLoaded) { | ||
// load from package.json | ||
loadPkgJSON(secrets, required) | ||
} | ||
loadNowJSON(secrets, required) | ||
} | ||
@@ -31,0 +24,0 @@ |
{ | ||
"name": "now-env", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Use `now.json` environment variables while developing", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# now-env | ||
With the help of this package, you can easily set environment variables for the use in development. | ||
If you're already using a `now.json` file or the `now` key in `package.json`, the `env` sub property will be assigned to `process.env` automatically. | ||
In addition, you can store secrets locally, that are specific to the development environment. | ||
**IMPORTANT:** Do not use this package in production. It should only be used locally, while developing. This is because the secrets that you're using locally shouldn't match the ones you use in production (more secure). In production, you should be adding secrets [like this](https://zeit.co/docs/getting-started/secrets). | ||
## Usage | ||
Firstly, install the package from [npm](https://www.npmjs.com/package/now-env): | ||
```bash | ||
yarn add now-env | ||
``` | ||
As the last step, register the helper by loading it: | ||
```js | ||
require('now-env') | ||
``` | ||
That's all, you can now check `process.env` for the environment variables! | ||
> If your application is running inside [Now](https://zeit.co/now) cloud then this module is not going to do anything and let Now set your environment variables. | ||
If using this with [Next.js](https://github.com/zeit/next.js), follow the example at [`next.js/examples/with-now-env`](https://github.com/zeit/next.js/tree/canary/examples/with-now-env) to make sure `now-env` only runs on the server at build time. | ||
### Secrets | ||
Most probably you will want to use [secret keys](https://zeit.co/docs/features/env-and-secrets#securing-env-variables-using-secrets) in your `now.json` file. This module allow you to use them too without worries in development. | ||
Create a `now.json` with some secret defined as `@secret-name`, similar to: | ||
```json | ||
{ | ||
"env": { | ||
"SECRET": "@my-secret-key", | ||
"ANOTHER_SECRET": "@my-other-secret-key", | ||
"SECRET_FAIL": "@this-is-not-defined" | ||
} | ||
} | ||
``` | ||
Then create a `now-secrets.json` with the secrets names and values. | ||
```json | ||
{ | ||
"@my-secret-key": "keep-it-secret", | ||
"@my-other-secret-key": "keep-it-secret-too" | ||
} | ||
``` | ||
> This file must be ignored to actually keep them **secret**. | ||
Then when starting your application `now-env` will read the `now.json` and get the values from `now-secrets.json`. If a environment key can't be found in `now-secrets.json` (or the file doesn't exists) then is going to use the secret name as value, that means if `DB_PASS` is `@db_pass` and you don't define it inside `now-secrets.json` then the value will be `@db_pass`. | ||
### Required Variables | ||
Now supports using the `env` key as an array of required values you'll need to provide when deploying. This module also allow you to use them in development. | ||
Create a `now.json` with the array, similar to: | ||
```json | ||
{ | ||
"env": [ | ||
"REQUIRED_KEY", | ||
"REQUIRED_SECRET" | ||
] | ||
} | ||
``` | ||
Then create a `now-required.json` with the environment keys and values. | ||
```json | ||
{ | ||
"REQUIRED_KEY": "required-value", | ||
"REQUIRED_SECRET": "@required-secret" | ||
} | ||
``` | ||
> You can also use secrets, for that you will need to create a `now-secrets.json` too. | ||
Then when starting your application `now-env` will read the `now.json` and get the values from `now-required.json` (and `now-secrets.json`). If a environment key can't be found in `now-required.json` then is going to throw a reference error. | ||
## Migrating from `dotenv` | ||
If you're already using the `dotenv` module you can switch to `now-env` easily: | ||
1. Create a `now.json` file with the `env` key with every environment variable | ||
2. Install `now-env` | ||
3. Change `require('dotenv').config()` with `require('now-env')` | ||
4. That's it! | ||
_This package has now been deprecated with the [release of `now dev`](https://zeit.co/blog/now-dev). We recommend setting environment variables either by [using a `.env` file](https://zeit.co/docs/v2/development/environment-variables/#using-a-.env-file), or inside a [`now.json` file](https://zeit.co/docs/v2/development/environment-variables/#using-now.json). For more information you should read the [full documentation](https://zeit.co/docs/v2/development/environment-variables)._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6421
10
144
4
1