[SOLVED] METEOR_SETTINGS not being passed to Meteor.settings in prod


#1

I having some trouble getting my settings.json to get passed to my production app. Everything is working in development, which uses the --settings flag for the same file I’m using in production. I’m running my own production server environment and having the node app run in an upstart script, where I set the METEOR_SETTINGS variable using

    METEOR_SETTINGS=$(cat /project/settings.json)
    echo "$METEOR_SETTINGS"

As you can see, I echo the var to make sure it’s getting set to the right value (which it is). Then I node main.js later on in the script and I tail the logs to see what’s going on.

TypeError: Cannot read property 'thing' of undefined
(STDERR)     at meteorInstall.server.methods.things.things.js (server/methods/things/things.js:11:32)

At first, I wasn’t sure what exactly was happening since I use Meteor.settings everywhere in my app and some of them are conditional based on Meteor.isProduction. However, after testing in development with meteor --production I see that the error is identical to when Meteor.settings is the default value { public: {} }.

I’ve seen plenty of posts on here and issues on the GitHub where people were confused as to which method of passing settings.json to the app to use in dev or prod, or people’s JSON being invalid, but this is definitely not my case, unfortunately. My JSON is 100% valid, and I’m using the same settings.json in both dev and prod. I fully understand that for prod, I need to use METEOR_SETTINGS and in dev, I need to use --settings. Meteor isn’t throwing any errors about my JSON being invalid, the contents of the file are just not being written to the Meteor.settings object, i.e. it’s just not working.

I’m refraining from opening an issue until I better understand what’s going on. Are there any gotchas concerning this usage? Has anyone else encountered these kinds of difficulties?


#2

Anyone else having this issue, using Upstart or some other job manager, here’s the solution (on Ubuntu 14.04)

METEOR_SETTINGS=$(cat /project/settings.json)
export METEOR_SETTINGS  # super important that you do this
echo "$METEOR_SETTINGS"

Using a tool like Upstart lets you run scripts inside jobs that run in their own isolated environments. Because of this, you need to export any environmental variables you define inside a script stanza so that they are accessible by the node process (or any other process you’re going to initiate in the job that relies on those vars).

This was a bit of a head scratcher for me, hope it helps anyone else using Upstart or any similar tools.


#3

I have the same trouble, but your solution didn’t help me. I use “service” to start my app (on Ubuntu 16.02) and Meteor.settings is still empty ({ public: {} }). When I try echo “$METEOR_SETTINGS” it shows me my settings object/json, but when I try
Meteor.startup(() => {
console.log(Meteor.settings);
});
nothing is shown from that json


#4

The syntax is probably different using Systemd. Look up what the syntax is to export a variable to the global environment, because it might not be export, might be something else.


#5

I have same trouble on my production.
I try echo “$METEOR_SETTINGS” it shows me my settings object/json correctly, but it show empty when log out in source code.
CentOS7
run:
export METEOR_SETTINGS={"key":"value",...} MONGO_URL=mongodb://xxxx:27017/pacs_wv ROOT_URL=http://localhost PORT=3000 node main.js

Anybody fixed it?


#6

Let us see how you are doing this in your code - also where are you logging it - client or server?


#7

Hi @robfallows,

I’m logging it on server site.

console.log(JSON.stringify(Meteor.settings, null, 2) )

log content:
{
“public”: {}
}

if I run it in dev environement. it work well (show all in my setting.json)
METEOR_PACKAGE_DIRS="…/Packages" ROOT_URL=http://localhost:3000 meteor --settings …/config/ClearCanvasDIMSE.json


#8

Try

METEOR_SETTINGS='{"key":"value"}'

#9

Thanks you so much @afrokick

It works well