Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Meteor's settings.json to connect to local MongoDB

Tags:

mongodb

meteor

I was breaking out some of the admin/management functionality from a Meteor app into another new one to cut down client app size/help restrict access. I also have MongoDB installed separately on localhost and in production.

I've been able to run each app on separate ports and to connect to the DB passing environment variables as I start the apps:

# App 1
MONGO_URL=mongodb://localhost:27107/appDB meteor 
# App 2
MONGO_URL=mongodb://localhost:27107/appDB meteor --port 4000

Of course, I'd like to use settings.json in the project root to pass these variables in rather than having to specify them (here's the settings.json for App 2):

{
    "env": {
        "PORT": 4000,
        "MONGO_URL": "mongodb://localhost:27017/appDB"
    }
}

And using meteor run --settings settings.json to pass these variables in. However, Meteor won't recognise the settings file. Any ideas where I might've gone wrong?

Update 1: @Apendua was kind enough to let me know that settings.json simply doesn't support this behaviour yet. Setting up bash aliases instead.

Update 2: @AshHimself pointed out that Galaxy can recognise environment variables in this fashion, but the core Meteor docs weren't terribly clear if this works in a local environment.

like image 237
mattpolicastro Avatar asked Oct 31 '22 05:10

mattpolicastro


1 Answers

I run my Meteor app with local MongoDB with bash script.

Go to your Meteor project directory and write this in your command line (BASH):

echo 'MONGO_URL=mongodb://localhost:27017/meteorprojectname meteor run' > run.sh

Change permissions of the script so you can run it without sudo:

sudo chmod 777 run.sh

And now you can just run your project with command:

./run.sh

More info: http://meteor.hromnik.com/blog/meteor-run-without-creating-local-mongo-database

like image 175
Tomas Hromnik Avatar answered Nov 15 '22 07:11

Tomas Hromnik