admin管理员组文章数量:1279234
Before you flame me, I've done my research (Javascript ENV variables). I know that it is not possible to access system environment variables using Javascript.
I'm using Yeoman to develop a Javascript library. That library is for use with Google Maps API and some of my tests require that Google Maps API as a dependency. To load the Google Maps API script, you need an API key. Now, my code is located on my Github and I really wouldn't like to have my API key as part of the code.
Is there any Node module that would be able to inject an environment variable into my tests when running Grunt? Are there any ENV variable equivalents in Node.js?
This is an example of a need for a JS ENV variable solution. There are other ways around the problem, but I am specifically looking for this type of a solution.
Edit: most importantly, how do I have these ENV variables auto load into my program when I run tests using grunt
Thank you!
Before you flame me, I've done my research (Javascript ENV variables). I know that it is not possible to access system environment variables using Javascript.
I'm using Yeoman to develop a Javascript library. That library is for use with Google Maps API and some of my tests require that Google Maps API as a dependency. To load the Google Maps API script, you need an API key. Now, my code is located on my Github and I really wouldn't like to have my API key as part of the code.
Is there any Node module that would be able to inject an environment variable into my tests when running Grunt? Are there any ENV variable equivalents in Node.js?
This is an example of a need for a JS ENV variable solution. There are other ways around the problem, but I am specifically looking for this type of a solution.
Edit: most importantly, how do I have these ENV variables auto load into my program when I run tests using grunt
Thank you!
Share Improve this question edited May 23, 2017 at 11:45 CommunityBot 11 silver badge asked Jan 23, 2014 at 22:29 connorbodeconnorbode 3,1592 gold badges30 silver badges32 bronze badges 2- Well, you can read environment variables with node.js - only a webpage loaded in a browser is not allowed too access the clients variables. However, I wouldn't use an env variable for my secret api keys :-) – Bergi Commented Jan 23, 2014 at 22:32
-
1
possible duplicate of How to store Node.js deployment settings/configuration files? - and include them in your
gitignore
file. – Bergi Commented Jan 23, 2014 at 22:37
1 Answer
Reset to default 8Yes, you can access the environment variables in a Node script via the process object.
console.log(process.env.secret_key);
Storing your API keys in environment variables is much better than doing so in your repo.
本文标签: nodejsENV Variable Equivalent in JavascriptStack Overflow
版权声明:本文标题:node.js - ENV Variable Equivalent in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741281562a2370038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论