Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically load settings.json on starting Meteor.js

Rather than starting Meteor with the flag --settings settings.json

mrt --settings settings.json

Is it possible to define Meteor.Settings automatically on startup by just running

mrt
like image 732
Nyxynyx Avatar asked Jan 09 '14 02:01

Nyxynyx


3 Answers

Nowadays the command should be meteor (no more mrt):

meteor --settings settings.json

To automatically load settings file, I like the method suggested on "The Meteor Chef" that exploits npm:

Creating a file package.json in the project root:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "meteor --settings settings.json"
  }
}

We can start meteor with:

npm start

DEV/PROD

Also it is possible to have two or more scripts for two or more settings:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "meteor:dev": "meteor --settings settings-dev.json",
    "meteor:prod": "meteor --settings settings-prod.json"
  }
}

Then:

npm run meteor:dev

or

npm run meteor:prod

(note that here we have to add the run command, not required with the "special" script start)

like image 166
Andrea Avatar answered Nov 11 '22 22:11

Andrea


For dev, use an alias

alias mrt='mrt --settings settings.json'

or

alias mrts='mrt --settings settings.json'

remove it with unalias mrts

When you want it to be permanent, put it in ~/.bashrc or ~/.bash_profile

Alternatively, meteor accepts an environment variable (useful for production)

METEOR_SETTINGS = `cat path/to/settings.json`
export METEOR_SETTINGS
like image 7
nathan-m Avatar answered Nov 11 '22 21:11

nathan-m


If you don't want to fiddle with aliases, you could create a bash script in the root directory of a specific project, like so:

dev.sh:

#!/bin/bash
meteor --settings ./config/development/settings.json

And just run it from the meteor project directory with:

./dev.sh

If you get -bash: ./dev.sh: Permission denied just do:

chmod +x ./dev.sh

If you use other services you could start them before meteor like so:

#!/bin/bash
sudo service elasticsearch start
meteor --settings ./config/development/settings.json
like image 4
Bjørn Bråthen Avatar answered Nov 11 '22 23:11

Bjørn Bråthen