![](/img/trans.png)
[英]How do I access the process.env object of the importing class in an imported npm package?
[英]How do I access process.env in Meteor?
我努力了:
alert(process.env.MONGO_URL);
無處不在是我的Meteor項目並始終得到:
Uncaught ReferenceError: process is not defined
我不確定我做錯了什么。 我需要包含一些東西嗎? Meteor是用javascript編寫的,所有相同的API都可用,為什么不定義流程呢?
你可以試試
if (Meteor.isServer) {
console.log(process.env);
}
您必須從服務器端獲取環境。 請嘗試以下方法。
//In the client side
if (Meteor.isClient) {
Meteor.call('getMongoUrlEnv', function(err, results) {
alert("Mongo_URL=",results);
});
}
if (Meteor.isServer) {
Meteor.methods({
getMongoUrlEnv: function(){
var mongoURL = process.env.MONGO_URL;
return mongoURL;
}
});
}
您可以使用此功能請求服務器端環境。
//In the client side
if (Meteor.isClient) {
Meteor.call('getEnv', "VARIABLE_NAME", function(err, results) {
alert(results);
});
}
if (Meteor.isServer) {
Meteor.methods({
getEnv: function(node){
return process.env[node];;
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.