Ok, so I am using node.js and it is awesome.
I have been working locally until very recently and I am a bit frustrated that I am changing my code each time just to deploy.
Specifically I am using socket io and I need to tell the socket where it lives:
var _socket = io.connect('http://localhost:5000');
When I have been going locally, this is great, but I need to change this each time I deploy to my test server...this is annoying. In other languages I can do this through a config file.
In node, on the server side, I can set variables based on my environment like so...
app.configure('development', function(){
process.env.PORT = 5000;
});
Can I do something similar on the client side?
You have to embed this variable to client-side HTML code somehow (i.e. in Jade templates).
If you show your server-side code serving HTML, I might be able to pinpoint where it might be.
I usually do stuff like this:
(function(){
var config = {
host: 'localhost',
port: '8080',
setEnv: function(env){
switch (env){
case 'development':
this.host = 'devserver';
this.port = '80';
break;
case 'production':
this.host = 'prodserver';
this.port = '80';
break;
}
}
};
console.log(config.host);
console.log(config.port);
config.setEnv('production');
console.log(config.host);
console.log(config.port);
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With