如何访问Meteor中的process.env?
我努力了:
alert(process.env.MONGO_URL);
到处都是我的Meteor项目,总是得到:
Uncaught ReferenceError: process is not defined
我不确定我做错了什么。 我需要包括什么吗? meteor是用JavaScript编写的,所有相同的API都可用,那么为什么不定义stream程呢?
你可以试试
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; } }); }
您可以使用此function请求服务器端环境。
//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];; } }); }