Gathering detailed insights and metrics for ember-cli-dotenv
Gathering detailed insights and metrics for ember-cli-dotenv
Gathering detailed insights and metrics for ember-cli-dotenv
Gathering detailed insights and metrics for ember-cli-dotenv
npm install ember-cli-dotenv
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
191 Stars
164 Commits
34 Forks
6 Watching
3 Branches
18 Contributors
Updated on 07 Oct 2024
Minified
Minified + Gzipped
JavaScript (90.53%)
HTML (9.05%)
Handlebars (0.27%)
CSS (0.16%)
Cumulative downloads
Total Downloads
Last day
-28.9%
1,561
Compared to previous day
Last week
-10.1%
8,904
Compared to previous week
Last month
-4%
43,171
Compared to previous month
Last year
11.2%
751,608
Compared to previous year
4
1
42
1ember install ember-cli-dotenv
ember install ember-cli-dotenv@^2.0.0
config/dotenv.js
and ember-cli-build.js
dotEnv
application options from ember-cli-build.js
to the function declared within config/dotenv.js
path
is dynamic see Multiple EnvironmentsThis was addon was designed to work with classic Ember CLI build pipeline and approach used here simply does not work under Embroider.
For Ember apps using Embroider, it's recommended to use @embroider/macros
to pass Node.js environment variable(s) to Ember code. In ember-cli-build.js
, do:
1require('dotenv').config(); 2 3let app = new EmberApp(defaults, { 4 '@embroider/macros': { 5 // this is how you configure your own package 6 setOwnConfig: { 7 DROPBOX_KEY: process.env.DROPBOX_KEY 8 }, 9 // this is how you can optionally send configuration into your 10 // dependencies, if those dependencies choose to use 11 // @embroider/macros configs. 12 setConfig: { 13 'some-dependency': { 14 DROPBOX_KEY: process.env.DROPBOX_KEY 15 }, 16 }, 17 }, 18});
In case if you need to consume env variable(s) only in FastBoot mode
and ensure they don't get transferred to browser in config/fastboot.js
, do:
1require('dotenv').config(); 2 3module.exports = function(environment) { 4 const myGlobal = { 5 DROPBOX_KEY: process.env.DROPBOX_KEY, 6 }; 7 8 return { 9 buildSandboxGlobals(defaultGlobals) { 10 return Object.assign({}, defaultGlobals, { 11 myGlobal, 12 }); 13 }, 14 }; 15}
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:
1DROPBOX_KEY=YOURKEYGOESHERE
Next, configure config/dotenv.js
.
1// config/dotenv.js 2module.exports = function(env) { 3 return { 4 clientAllowedKeys: ['DROPBOX_KEY'], 5 // Fail build when there is missing any of clientAllowedKeys environment variables. 6 // By default false. 7 failOnMissingKey: false 8 }; 9};
All keys in .env
are currently injected into node’s process.env
.
These will be available in your config/environment.js
file:
1// config/environment.js 2module.exports = function(environment) { 3 return { 4 MY_OTHER_KEY: process.env.MY_OTHER_KEY 5 }; 6};
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. Never include sensitive variables in clientAllowedKeys
, as these will
be exposed publicly via Ember's <meta name="app/config/environment">
tag.
Then, you can access the environment variables anywhere in your app like you usually would.
1import ENV from "my-app/config/environment"; 2 3console.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.
This addon supports FastBoot via fastbootConfigTree
build hook (requires ember-cli-fastboot
1.1.0 or higher).
Use fastbootAllowedKeys
configuration option to make variables available in FastBoot mode
when Ember application is rendered server-side.
1// ember-cli-build.js 2 3module.exports = function(defaults) { 4 let app = new EmberApp(defaults, { 5 dotEnv: { 6 clientAllowedKeys: ['DROPBOX_KEY'], 7 fastbootAllowedKeys: ['MY_API_SECRET', 'MY_OTHER_API_SECRET'] 8 } 9 }); 10 11 return app.toTree(); 12};
Note: keys listed in fastbootAllowedKeys
are not added to Ember's
<meta name="app/config/environment">
tag and are not available to Ember application
when it runs in browser.
Sometimes people may want to use different .env
file than the one in project root.
This can be configured as below:
1// config/dotenv.js 2module.exports = function(env) { 3 return { 4 clientAllowedKeys: ['DROPBOX_KEY'], 5 path: './path/to/.env' 6 }; 7};
In addition, you may also customize for different environments:
1// config/dotenv.js 2module.exports = function(env) { 3 return { 4 clientAllowedKeys: ['DROPBOX_KEY'], 5 path: `./path/to/.env-${env}` 6 }; 7};
With the above, if you run ember build --environment production
, the file
./path/to/.env-production
will be used instead.
Sometimes people may want to only initiate the dotenv file in one or more environments (e.g. not in production) This can be configured as below:
1// config/dotenv.js 2module.exports = function(env) { 3 return { 4 enabled: env !== 'production' // default is TRUE for any environment 5 }; 6};
When enabled
is set to false
, the dotenv protocol will not be used at all.
This is great for quieting errors and side issues when deploying with a service like Heroku,
where you can use environment variables set within the service and avoid storing a .env file in your repo.
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.
For FastBoot support you need Ember 2.3 or higher (2.12.0 and higher is prefereable by ember-cli-fastboot) and ember-cli-fastboot 1.1.1 or higher.
See the Contributing guide for details.
This project is licensed under the MIT License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 1/14 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More