Environment Variables Not Working


#1

I’m trying to pass in some keys using environment variables, but the environment variables don’t seem to go through. The app works fine when I have the keys in a Meteor settings file, but swapping the Meteor.settings.aws.key object with process.env.AWS_KEY breaks functionality. Any idea what I’m doing wrong?

I set the variable like this:

export AWS_KEY="key"
meteor --settings settings.json

and I call it server-side in my app like this:

process.env.AWS_KEY

I notice that I get this error in the developer console when I use environment variables:

Error logging in with token: Error: You've been logged out by the server. Please log in again. [403]

Any insights would be appreciated. Thanks!


#2

What does Meteor put out on the command line if you add a line :

console.log("AWS_KEY :: " + process.env.AWS_KEY);

#3

Is this during development or production? Meteor treats this differently according to the docs

Meteor.settings contains deployment-specific configuration options. You can initialize settings by passing the --settings option (which takes the name of a file containing JSON data) to meteor run or meteor deploy. When running your server directly (e.g. from a bundle), you instead specify settings by putting the JSON directly into the METEOR_SETTINGS environment variable. If the settings object contains a key named public, then Meteor.settings.public will be available on the client as well as the server. All other properties of Meteor.settings are only defined on the server. You can rely on Meteor.settings and Meteor.settings.public being defined objects (not undefined) on both client and server even if there are no settings specified. Changes to Meteor.settings.public at runtime will be picked up by new client connections.


#4

My issue isn’t with setting environment variables in the settings file; it’s with exporting environment variables from the command line. So, I would expect that I can do export AWS_KEY=“abc123” from the command line, do meteor run, and then any part of my server-side code that uses process.env.AWS_KEY should have the exported value.


#5

That works on my setup. Any environment variable I export in the shell I launch meteor in shows in process.env