Nyxynyx
Nyxynyx

Reputation: 63619

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

Upvotes: 9

Views: 5361

Answers (3)

Andrea
Andrea

Reputation: 16560

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)

Upvotes: 11

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

Upvotes: 4

nathan-m
nathan-m

Reputation: 8865

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

Upvotes: 7

Related Questions