Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass command line arguments to a Meteor app?

Tags:

meteor

I would like to pass command line arguments to my Meteor app on start up.

For example --dev, --test or --prod indicating whether or not it is running in dev, test or prod environments. It can then load different resources on start up, etc...

I tried something like this in a /server/server.js

var arguments = process.argv.splice(2);
console.log('cmd args: ' + JSON.stringify(arguments,0,4));

The I ran a test. And quite a few others with just random command line arguments.

meteor --dev

The output in the console is only this.

cmd args: [
    "--keepalive"
]

What is the best way to get command line arguments into a Meteor app?

Or, is this even the correct way to solve the higher level problem? and if not, what is the correct way to solve this problem of distinguishing between running enviro?

like image 224
Steeve Cannon Avatar asked May 06 '12 13:05

Steeve Cannon


1 Answers

Meteor doesn't forward command line args to your app, if it doesn't know them. You have multiple possibilities:

  1. Rewrite parts of meteor.js to forward unrecognized args. This shouldn't be too hard, but it's not a pretty solution. And if updates occur you are in trouble. :D
  2. You could write a small config file and change the behaviour of your app based on the configuration options in there. Take a look at this question.
  3. The easiest thing to do is using environment variables. You can read env vars in node like this. After that you can start your app the "express.js" way: $ METEOR_ENV=production meteor

I hope I could help you! :)

like image 66
jsbeckr Avatar answered Sep 21 '22 17:09

jsbeckr