2013-01-15 51 views
6

我曾嘗試:如何訪問Meteor中的process.env?

alert(process.env.MONGO_URL); 

到處是我的流星項目,一定可以得到:

Uncaught ReferenceError: process is not defined 

我不知道我在做什麼錯。我需要包括什麼嗎?流星是用JavaScript編寫的,所有相同的API都可用,所以爲什麼不定義流程?

+1

的重複[檢測環境Meteor.js?](http://stackoverflow.com/questions/14184643/detecting-environment-with-meteor-js) –

回答

7

你可以嘗試

if (Meteor.isServer) { 
    console.log(process.env); 
} 
4

您必須從服務器端環境。嘗試以下操作。

//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; 
     } 
    }); 
} 
0

您可以使用此功能請求服務器端環境。

//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];; 
     } 
    }); 
} 
相關問題