Reputation: 7998
I have two pieces of code: one that must only be run in a local environment and the other in production. What is the best way to do that in Meteor?
Upvotes: 2
Views: 311
Reputation: 1776
Use this package and you will haveMeteor.isdevelopment
only in development. There is other packages out there too that do the same thing but differently. this is the simplest
Upvotes: 0
Reputation: 75945
You can check do
(server side)
var isDevelopment = function() {
var i = WebApp.clientProgram.manifest.length;
while(i--) {
if('sourceMap' in WebApp.clientProgram.manifest[i]) return true;
}
return false;
}
if(isDevelopment()) {
console.log("Dev mode");
}else{
console.log("Production");
}
The idea is to check for JS Source Maps, which are only available in dev mode. This should work out of the box with your meteor app without any special configuration.
Upvotes: 3
Reputation: 64312
I prefer to set an environment variable which the server can read. For example:
$ METEOR_ENV="production" meteor
Then on the server:
if (process.env.METEOR_ENV === 'production') {
// production code here
} else {
// dev code here
}
If you have only two states, you could assume !production = dev.
Upvotes: 1