How to use habitat - 10 common examples

To help you get started, we’ve selected a few habitat 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 mozilla / webmaker-core / npm_tasks / build-config.js View on Github external
var habitat = require('habitat');

// Local environment in .env overwrites everything else
habitat.load('.env');

var environment = habitat.get('NODE_ENV', '').toLowerCase();

if (environment === 'production') {
  habitat.load('config/production.env');
}

habitat.load('config/defaults.env');

var config = {
  CLIENT_ID: habitat.get('CLIENT_ID'),
  API_URI: habitat.get('API_URI'),
  LOGIN_URI: habitat.get('LOGIN_URI')
};

process.stdout.write(
github mozilla / webmaker-android / npm_tasks / build-config.js View on Github external
var habitat = require('habitat');
var git = require('git-rev-sync');

// Local environment in .env overwrites everything else
habitat.load('.env');

var environment = habitat.get('NODE_ENV', '').toLowerCase();

if (environment === 'production') {
  habitat.load('config/production.env');
}

habitat.load('config/defaults.env');

var config = {
  CLIENT_ID: habitat.get('CLIENT_ID'),
  API_URI: habitat.get('API_URI'),
  LOGIN_URI: habitat.get('LOGIN_URI'),
  GIT_REVISION: git.short()
};
github mozilla / webmaker-android / gulp / config.js View on Github external
module.exports = function () {
  // Load configuration
  var env = process.env.NODE_ENV;
  habitat.load('.env');
  if (env === 'MOFODEV') {
    habitat.load('./config/mofodev.env');
  } else if (env === 'STAGING' || env === 'NPM') {
    habitat.load('./config/staging.env');
  }
  habitat.load('./config/defaults.env');

  var keys = Object.keys(process.env);
  var all = {};

  keys.forEach(function (key) {
    if (expose.indexOf(key) > -1) {
      all[key] = habitat.get(key);
    }
  });
github mozilla / thimble.mozilla.org / server / lib / environment.js View on Github external
/* jshint newcap:false */
var habitat = require("habitat");
habitat.load(require("path").resolve(__dirname, "../../.env"));
var env = new habitat();

module.exports = env;
github mozilla / makedrive / server / lib / environment.js View on Github external
// XXX: habitat overwrites process env variables with what's in .env
// making it impossible to do `LOG_LEVEL=... npm start` and defining
// a variable just for the lifetime of a command.  Here we check what's
// on the env first, and fix it if it gets overwritten.
var LOG_LEVEL = process.env.LOG_LEVEL;

var habitat = require('habitat');
habitat.load(require('path').resolve(__dirname, '../../.env'));
var env = new habitat();

// Fix-up LOG_LEVEL if present on env and different than habitat's
if(LOG_LEVEL) {
  var hLOG_LEVEL = env.get('LOG_LEVEL');
  if(hLOG_LEVEL && hLOG_LEVEL !== LOG_LEVEL) {
    env.set('LOG_LEVEL', LOG_LEVEL);
  }
}

module.exports = env;
github mozilla / api.webmaker.org / scripts / migrate.js View on Github external
// pass the path to the env file to load when invoking the script
// i.e. `npm run migrate -- tests.env`
require('habitat').load(process.argv[2]);

var url = require('url');
var Hoek = require('hoek');
var spawn = require('cross-spawn');
var BPromise = require('bluebird');
var fs = BPromise.promisifyAll(require('fs'));
var path = require('path');

var defaults = {
  // default account has no password. Except on Windows, where it asks for a password during installation
  POSTGRE_CONNECTION_STRING: 'postgre://postgres@localhost:5432/webmaker'
};

process.env = Hoek.applyToDefaults(defaults, process.env);

var pgConnString = url.parse(process.env.POSTGRE_CONNECTION_STRING);
github mozilla / api.webmaker.org / test / mocks / server.js View on Github external
require('habitat').load('tests.env');

var Hapi = require('hapi');
var TOKENS = require('./tokens');

function mockTokenValidator(token, callback) {
  var t = TOKENS[token];
  callback(null, !!t, t);
}

module.exports = function(done) {
  var server = new Hapi.Server();
  server.connection();

  server.register(require('hapi-auth-bearer-token'), function(err) {
    if ( err ) {
      throw err;
github mozilla / id.webmaker.org / test / web.js View on Github external
require("habitat").load("tests.env");

var Code = require("code");
var Lab = require("lab");
var lab = exports.lab = Lab.script();

var loginServer = require("./mock-login/server");
var server = require("../web/server");
var testCreds = require("./testCredentials");
var url = require("url");

lab.experiment("OAuth", function() {
  var s, s2, ls;
  const cookieSecret = "test".padEnd(32, "test");

  lab.before(async () => {
    const loginAPI = `http://${process.env.HOST}:3232`;
github mozilla / learning.mozilla.org / config / webpack / webpack.client.config.js View on Github external
/**
 * This is the webpack configuration for generating the
 * learning.mozilla.org client-side bundle that is loaded
 * in the user's browser when they visit any of our pages.
 */

var webpack = require('webpack');
var production = process.env.NODE_ENV === 'production';
var habitat = require('habitat');

habitat.load('.env');

function importEnvVars(keys) {
  var result = {};

  keys.forEach(function(key) {
    if (typeof (process.env[key]) === 'string') {
      result['process.env.' + key] = JSON.stringify(process.env[key]);
    }
  });
  return result;
}

var webpackConfig = {
  entry: {
    client: __dirname + '/../../lib/build/client.bundle.jsx'
  },
github mozilla / learning.mozilla.org / config / webpack / webpack.client.config.js View on Github external
/**
 * This is the webpack configuration for generating the
 * learning.mozilla.org client-side bundle that is loaded
 * in the user's browser when they visit any of our pages.
 */

var webpack = require('webpack');
var production = process.env.NODE_ENV === 'production';
var habitat = require('habitat');

habitat.load('.env');

function importEnvVars(keys) {
  var result = {};

  keys.forEach(function(key) {
    if (typeof (process.env[key]) === 'string') {
      result['process.env.' + key] = JSON.stringify(process.env[key]);
    }
  });
  return result;
}

var webpackConfig = {
  entry: {
    client: __dirname + '/../../lib/build/client.bundle.jsx'
  },

habitat

Small library for managing environment variables

MIT
Latest version published 9 years ago

Package Health Score

46 / 100
Full package analysis

Popular habitat functions