How to use the dotenv-safe.config function in dotenv-safe

To help you get started, we’ve selected a few dotenv-safe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nicolaschan / bell / scripts / locator.js View on Github external
// Gets a list of all the cities that we get hits from
require('dotenv-safe').config()

const config = {
  postgres: {
    user: process.env.POSTGRES_USER,
    host: process.env.POSTGRES_HOST,
    database: process.env.POSTGRES_DATABASE,
    password: process.env.POSTGRES_PASSWORD,
    port: process.env.POSTGRES_PORT
  }
}
const logger = require('loggy')

if (process.env.POSTGRES_ENABLED !== 'true') {
  logger.error('Postgres is disabled')
  process.exit(1)
}
github 0xTracker / 0x-tracker-worker / src / index.js View on Github external
// Load environment variables from .env in development and throw an
// error if any required variables are missing in production
require('dotenv-safe').config({
  example:
    process.env.NODE_ENV === 'production'
      ? '.env.prod.example'
      : '.env.example',
});

const { logError } = require('./util/error-logger');
const app = require('./app');

app
  .initialise()
  .then(() => app.start())
  .catch(logError);
github keystonejs / keystone / cypress / scripts / utils.js View on Github external
// Inject the prefix onto the keys
  required = Object.keys(required).reduce(
    (memo, requiredKey) =>
      Object.assign(memo, {
        [`${ciEnvPrefix}${requiredKey}`]: required[requiredKey],
      }),
    {}
  );

  // write back to a temporary file
  const tmpobj = tmp.fileSync();
  fs.writeFileSync(tmpobj.fd, envfile.stringifySync(required));

  // Use that temporary file as the 'expected env' vars
  const envVars = dotEnvSafe.config({
    example: tmpobj.name,
  });

  if (envVars.error) {
    // TODO: Better error with info on how to set the correct env vars
    throw new Error(envVars.error);
  }

  // The loaded env vars with the prefix removed
  const loadedEnvVars = Object.keys(envVars.parsed)
    .filter(key => key.startsWith(ciEnvPrefix))
    .reduce(
      (memo, key) =>
        Object.assign(memo, {
          [key.replace(ciEnvPrefix, '')]: envVars.parsed[key],
        }),
github cdmbase / fullstack-pro / servers / frontend-server / .zenrc.js View on Github external
config.options.devProxy = config.options.ssr;

const extraDefines = {
    __SSR__: config.options.ssr,
    __PERSIST_GQL__: `'${config.options.persistGraphQL}'`,
    __FRONTEND_BUILD_DIR__: `'${config.options.frontendBuildDir}'`,
    __DLL_BUILD_DIR__: `'${config.options.dllBuildDir}'`,
    __DEBUGGING__: `'${debug}'`
};

if (process.env.NODE_ENV !== 'production') {

    if (!config.options.ssr) {
        console.log('Warning! exposing env variables in UI, only run in development.');
        var dotenv = require('dotenv-safe')
            .config(
                {
                    allowEmptyValues: true,
                    path: process.env.ENV_FILE,
                    example: '../../config/development/dev.env',
                });
        const envConfig = {
            plugins: [
                new webpack.DefinePlugin({
                    "__ENV__": JSON.stringify(dotenv.parsed)
                }),
            ],
        }
        config.builders.web.webpackConfig = merge(config.builders.web.webpackConfig, envConfig);
    }
}
github 0xTracker / 0x-tracker-worker / jest / setup.js View on Github external
require('dotenv-safe').config({
  example: '.env.test.example',
});

const signale = require('signale');

signale.disable();
github nicolaschan / bell / server / api-server.js View on Github external
require('dotenv-safe').config()

const logger = require('loggy')
const express = require('express')
const http = require('http')
const app = express()
const compression = require('compression')
app.use(compression())
const server = http.createServer(app)
const register = require('./register')
const checkForNewVersion = require('./updates')

app.use('/api/data', require('./api/data'))

function startWebServer () {
  return new Promise((resolve, reject) => {
    server.listen(process.env.WEBSERVER_PORT, err => {
github nicolaschan / bell / scripts / sqlite2pg.js View on Github external
require('dotenv-safe').config()

const path = require('path')
const UAParser = require('useragent')
const { Pool } = require('pg')
const pgDb = new Pool({
  user: process.env.POSTGRES_USER,
  host: process.env.POSTGRES_HOST,
  database: process.env.POSTGRES_DATABASE,
  password: process.env.POSTGRES_PASSWORD,
  port: process.env.POSTGRES_PORT
})
const Database = require('better-sqlite3')
const sqliteDb = new Database(path.join(__dirname, '..', 'analytics.sqlite'))

const pgHandler = require('../server/api/analytics/PostgresAnalyticsHandler.js')
github streamr-dev / streamr-platform / marketplace / scripts / dotenv.js View on Github external
const getDotenvPlugin = (commonDotenvPath, localDotenvPath, isProduction) => {
    const localDotenv = !isProduction ? dotenv.config({
        example: null,
        path: localDotenvPath,
    }) : {}

    const commonDotenv = dotenvSafe.config({
        example: commonDotenvPath,
        path: !isProduction ? commonDotenvPath : null,
    })

    return new webpack.EnvironmentPlugin([
        ...Object.keys(commonDotenv.required || {}),
        ...Object.keys(localDotenv.parsed || {}),
    ])
}

dotenv-safe

Load environment variables from .env and ensure they are defined

MIT
Latest version published 9 months ago

Package Health Score

72 / 100
Full package analysis

Popular dotenv-safe functions