How to use dotenv - 10 common examples

To help you get started, we’ve selected a few dotenv 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 cnguy / kayn / test / specs / endpoints / matchlist.specs.js View on Github external
/* eslint-disable max-nested-callbacks */
var chai = require('chai')

var expect = chai.expect,
  should = chai.should,
  assert = chai.assert

require('dotenv').config()

var init = require('../../../utils/init')

const name = 'Contractz'
const id = 32932398
const accId = 47776491
const options = {
  queue: [420, 440],
  champion: 79
}
const region = 'na'

const badConfig = {
  options: {
    Queue: 420 // instead of queue
  }
github johnnyvf24 / hellochess-v2 / server / sockets / listeners / room.ts View on Github external
const Notifications = require('react-notification-system-redux');

import Player from '../../game_models/players/Player';
import AI from '../../game_models/players/AI';
import Room from '../../game_models/rooms/Room';
import Game from '../../game_models/games/Game';
import {Message, ResignMessage, AbortMessage} from '../../game_models/rooms/Message';

//Game Rules
import FourGame from '../../game_models/games/FourGame';
import Standard from '../../game_models/games/Standard';
import CrazyHouse from '../../game_models/games/CrazyHouse';

//server environment
const dotenv = require('dotenv').load();

const env = process.env.NODE_ENV || "development";

module.exports = function(io, socket, connection) {
    
    socket.on('new-message', data => {
        let roomName: string = data.thread;
        let player: Player = connection.getPlayerBySocket(socket);
        let room: Room = connection.getRoomByName(roomName);
        if(!room) return;
        
        //add the message to the room
        room.addMessage(new Message(player, data.msg, roomName));
        
        // tell everyone there is a new message
        io.to(room.name).emit('update-room-full', room.getRoomObjFull());
github sanity-io / sanity / packages / @sanity / webpack-integration / src / v3 / index.js View on Github external
function tryReadDotEnv(studioRootPath, configEnv) {
  const envFile = path.join(studioRootPath, `.env.${configEnv}`)

  let parsed = {}
  try {
    // eslint-disable-next-line no-sync
    parsed = dotenv.parse(fs.readFileSync(envFile, {encoding: 'utf8'}))
  } catch (err) {
    if (err.code !== 'ENOENT') {
      // eslint-disable-next-line no-console
      console.error(`There was a problem processing the .env file (${envFile})`, err)
    }
  }

  return parsed
}
github zeit / now / src / util / dev / server.ts View on Github external
async getLocalEnv(fileName: string, base?: EnvConfig): Promise {
    // TODO: use the file watcher to only invalidate the env `dotfile`
    // once a change to the `fileName` occurs
    const filePath = join(this.cwd, fileName);
    let env: EnvConfig = {};
    try {
      const dotenv = await fs.readFile(filePath, 'utf8');
      this.output.debug(`Using local env: ${filePath}`);
      env = parseDotenv(dotenv);
    } catch (err) {
      if (err.code !== 'ENOENT') {
        throw err;
      }
    }
    try {
      this.validateEnvConfig(fileName, base || {}, env);
    } catch (err) {
      if (err instanceof MissingDotenvVarsError) {
        this.output.error(err.message);
        await this.exit();
      } else {
        throw err;
      }
    }
    return { ...base, ...env };
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / validate-environment.js View on Github external
default: true
        })
    };
    if (process.env.NODE_ENV !== 'production') {
        validation.MAGENTO_BACKEND_URL = url({
            desc: 'Public base URL of of Magento 2.3 instance.',
            example: 'https://magento2.vagrant65'
        });
        const { readFileSync } = require('fs');
        const path = require('path');
        const chalk = require('chalk');
        const dotenv = require('dotenv');
        let parsedEnv;
        const envPath = path.join(__dirname, '.env');
        try {
            parsedEnv = dotenv.parse(readFileSync(envPath));
            // don't use console.log, which writes to stdout. writing to stdout
            // interferes with webpack json output
            console.warn(
                chalk.green(
                    `Using environment variables from ${chalk.greenBright(
                        '.env'
                    )}`
                )
            );
            if (env.DEBUG || env.NODE_DEBUG) {
                console.warn(
                    '\n  ' +
                        require('util')
                            .inspect(parsedEnv, {
                                colors: true,
                                compact: false
github async-labs / saas / book / 13-end / app / server / env.ts View on Github external
// Only import this file once, at entrypoint
// See https://github.com/motdotla/dotenv/tree/master/examples/typescript

import { config } from 'dotenv';

const result = config();
// Only override process.env if .env file is present and valid
if (!result.error) {
  Object.keys(result.parsed).forEach((key) => {
    const value = result.parsed[key];
    if (value) {
      process.env[key] = value;
    }
  });
}
github async-labs / saas / book / 9-begin / api / server / env.ts View on Github external
// Only import this file once, at entrypoint
// See https://github.com/motdotla/dotenv/tree/master/examples/typescript

import { config } from 'dotenv';
const result = config();

// Only override process.env if .env file is present and valid
if (!result.error) {
  Object.keys(result.parsed).forEach((key) => {
    const value = result.parsed[key];
    if (value) {
      process.env[key] = value;
    }
  });
}
github shaunymca / coffeeapp / modules / slackPosting.js View on Github external
var slack = require('slack'),
    Q = require("q"),
    async = require('async');
require('dotenv').config();
var SlackApiToken = process.env.SLACKKEY
var coffee_channel = process.env.COFFEECHANNEL

//for testing slackbottest channel
var testing_channel = process.env.TESTINGCHANNEL

exports.postBrewing = function(user_name, user_id) {
  var botname = 'Coffee Bot'
  var icon_emoji = ":coffeemug:"
  var user_mention = '<@' + user_id + '|' + user_name +'>'
  var twelveMins = 12 * 60 * 1000 // 12 minutes to brew a pot
  var text = user_mention + ' just started brewing a pot :coffee:'
  slack.chat.postMessage({ token:SlackApiToken, channel:coffee_channel, text:text, icon_emoji:icon_emoji, username:botname}, function(err, data) {
    setTimeout(function() {
      var text = 'Coffee is ready. Thanks ' + user_mention + ' for brewing it. :coffee:'
      slack.chat.postMessage({ token:SlackApiToken, channel:coffee_channel, text:text, icon_emoji:icon_emoji, username:botname}, function(err, data) {
github npm / captain-hook / index.js View on Github external
// load the env file
require('dotenv').load();
var port = process.env.PORT || '6666';

// how we log
const logger = require("./src/lib/logger").logger;
const logHandler = require("./src/lib/logger").logHandler;

// how we receive npm hooks
const server = require("./src/lib/hook_receiver");

// how we post to slack
const slack = require('./src/lib/slack_client').client;
const channelID = require('./src/lib/slack_client').channelID;

// routes live in a separate place
const routes = require('./src/routes');
github DCtheTall / node-video-chat / config / config.js View on Github external
if (!process.env.NODE_ENV) require('dotenv').load(); // eslint-disable-line

const config = {
  development: {
    dialect: 'postgres',
    database: process.env.DATABASE_NAME,
    host: process.env.DATABASE_HOST,
    username: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    port: 5432,
  },
  production: {
    dialect: 'postgres',
    dialectOptions: {
      ssl: true,
    },
    use_env_variable: 'DATABASE_URL',

dotenv

Loads environment variables from .env file

BSD-2-Clause
Latest version published 18 days ago

Package Health Score

91 / 100
Full package analysis