Giter Club home page Giter Club logo

ember-cli-dotenv's Introduction

Build Status

Ember CLI Dotenv

Installation

ember install ember-cli-dotenv

What is Ember CLI Dotenv?

This addon allows you to write environment variables in a .env file and expose them to your Ember app through the built-in config/environment.js that you can import in your app. For example, you might be building an app with Dropbox and don’t want to check your key into the repo. Put a .env file in the root of your repository:

DROPBOX_KEY=YOURKEYGOESHERE

Next, put some configuration in your ember-cli-build.js. Starting in 0.2.0, client side keys must be explicitly allowed:

// ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    dotEnv: {
      clientAllowedKeys: ['DROPBOX_KEY']
    }
  });

  return app.toTree();
};

All keys in .env are currently injected into node’s process.env. These will be available in your config/environment.js file:

// config/environment.js
module.exports = function(environment){
  return {
    MY_OTHER_KEY: process.env.MY_OTHER_KEY
  }
};

You can then use the node process environment variables in other ember-cli-addons, such as express middleware or other servers/tasks.

Security: environment variables in config/environment.js are never filtered unlike using .env and clientAllowedKeys. Remember to use the environment variable passed into your config function to filter out secrets for production usage.

then, you can access the environment variables anywhere in your app like you usually would.

import ENV from "my-app/config/environment";

console.log(ENV.DROPBOX_KEY); // logs YOURKEYGOESHERE

You can read more about dotenv files on their dotenv repository.

All the work is done by ember-cli and dotenv. Thanks ember-cli team and dotenv authors and maintainers! Thanks Brandon Keepers for the original dotenv ruby implementation.

Multiple Environments

Sometime people may want to use different .env file than the one in project root. This can be configured as below:

// ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    dotEnv: {
      clientAllowedKeys: ['DROPBOX_KEY'],
      path: './path/to/.env'
    }
  });

  return app.toTree();
};

In addition, you may also customize for different environments:

// ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    dotEnv: {
      clientAllowedKeys: ['DROPBOX_KEY'],
      path: {
        development: './path/to/.env',
        test: './path/to/.env.test',
        production: './path/to/.env.production'
      }
    }
  });

  return app.toTree();
};

With the above, if you run ember build --environment production, the file .env.production will be used instead.

Compatibility

This addon supports the Ember 2.x series, but it is also backwards-compatible down to Ember-CLI 0.1.2 and Ember 1.7.0.

Other Resources

Development Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

ember-cli-dotenv's People

Contributors

dschmidt avatar elwayman02 avatar fivetanley avatar gniquil avatar jasonmit avatar jeffreybiles avatar matthewlehner avatar opsb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.