Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access process.env in Meteor?

I have tried:

alert(process.env.MONGO_URL);

everywhere is my Meteor project and always get:

Uncaught ReferenceError: process is not defined 

I'm not sure what I'm doing wrong. Do I need to include something? Meteor is written in javascript and all the same APIs are available so why isn't process defined?

like image 349
nickponline Avatar asked Jan 15 '13 17:01

nickponline


People also ask

How can I see the process environment variable?

Solved: start by typing node and pressing enter, then type process. env and press enter.

Where are process env variables stored?

Environment variables are stored in your system shell that you start node. js from. They are a shell feature that node.

What is process env path?

The process. env global variable is injected by the Node at runtime for your application to use and it represents the state of the system environment your application is in when it starts. For example, if the system has a PATH variable set, this will be made accessible to you through process. env.

How do I view a node environment?

To retrieve environment variables in Node. JS you can use process. env. VARIABLE_NAME, but don't forget that assigning a property on process.


2 Answers

You could try

if (Meteor.isServer) {
  console.log(process.env);
}
like image 128
Werner Kvalem Vesterås Avatar answered Oct 07 '22 17:10

Werner Kvalem Vesterås


You must get the environment from the server side. Try the following.

//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;
      }
   });
}
like image 29
Vince Avatar answered Oct 07 '22 17:10

Vince