1

I'm adding security for my API keys with the Meteor package dotenv: https://github.com/okgrow/meteor-dotenv as per instructions, I: 1. created a file named ".env" in my root 2. entered two keys in the style "THIS_KEY=BLAH12345" in the file 3. made a meteor call function returning process.env.THIS_KEY for the client side to use.

I'm getting Referenceerror: process.env is not defined. For just plain node there are a lot of answers out there, but not so for Meteor. Did I name my file incorrectly? Need to use a Meteor command to activate something?

2 Answers2

2

I ran into this same problem, and have made it work by putting the

var secretThing = process.env.SECRET_THING

server side, inside the if (Meteor.isServer) and then passing the variable as a parameter to the method that needs to use the secret thing.

Meteor.call("apiCall", secretThing);

Then the receiving method looks like this:

    apiCall: function (secretThing) {
        console.log(secretThing);
    }
soc
  • 71
  • 9
-1

DotEnv is designed to read environment variables from a .env file, normally located in the root of your NodeJS application.

DotEnv just makes the variables it finds in the .env file available with the rest of the host systems environment variables through process.env

The problem is, I don't believe meteor supports .env files. This is probably due to the age of the application. I personally believe they should make rectifying this a priority.

The only way you can use process.env in a meteor app is to set the variables you want to use on the host system. If you are using linux it would be something like

export DB_PASSWORD=12345

You should then be able to use process.env to read DB_PASSWORD when your application is running.

// You can only run process.env in server code

if (Meteor.isServer) {
   const myDBPassword = process.env.DB_PASSWORD
}
PrestonDocks
  • 4,851
  • 9
  • 47
  • 82