Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

now-env

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

now-env - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

example/now-secrets.json

4

example/now.json
{
"env": {
"NODE_ENV": "production",
"TEST": "my-test-env"
"TEST": "my-test-env",
"SECRET": "@my-secret-key",
"SECRET_FAIL": "@this-is-not-defined"
}
}

@@ -11,5 +11,6 @@ {

"NODE_ENV": "production",
"TEST": "my-test-env"
"TEST": "my-test-env",
"SECRET": "@my-secret-key"
}
}
}

@@ -6,23 +6,42 @@ 'use strict'

const applyEnv = env => Object.keys(env).forEach(key => {
process.env[key] = env[key]
})
const applyEnv = (env, secrets) => {
for (const key in env) {
// if the key already exists don't overwrite it
if (!process.env[key]) {
const value = secrets[env[key]] || env[key]
process.env[key] = value
}
}
}
const loadSecrets = () => {
const SECRET_PATH = resolve('./now-secrets.json')
if (existsSync(SECRET_PATH)) {
return require(SECRET_PATH)
}
return {}
}
const config = () => {
const NOW_PATH = resolve('./now.json')
// only run this in a non-production environment
if (process.env.NODE_ENV !== 'production') {
const secrets = loadSecrets()
if (existsSync(NOW_PATH)) {
const nowFile = require(NOW_PATH)
const NOW_PATH = resolve('./now.json')
if (nowFile.env) {
return applyEnv(nowFile.env)
if (existsSync(NOW_PATH)) {
const nowFile = require(NOW_PATH)
if (nowFile.env) {
return applyEnv(nowFile.env, secrets)
}
}
}
const PKG_PATH = resolve('./package.json')
const PKG_PATH = resolve('./package.json')
const pkgFile = require(PKG_PATH)
const pkgFile = require(PKG_PATH)
if (pkgFile.now && pkgFile.now.env) {
return applyEnv(pkgFile.now.env)
if (pkgFile.now && pkgFile.now.env) {
return applyEnv(pkgFile.now.env, secrets)
}
}

@@ -29,0 +48,0 @@ }

{
"name": "now-env",
"version": "1.0.2",
"version": "1.1.0",
"description": "Use now.sh environment variables in development",

@@ -5,0 +5,0 @@ "keywords": [

@@ -23,1 +23,8 @@ # now-env

Because [now.sh](https://now.sh) automatically run your app with the `now.json` environment variables then this module it's not going to do anything in production :)
## Using 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.
Just create a `now-secrets.json` file with you development secrets, that file can (and most probably) be ignored with Git, then just use `now-env` as usual and it will auto-detect the file and use it to replace your secrets values.
If the file doesn't exists or if your secret key is not defined then it's going to use the key name as value for your environment variable.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc