Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  55] [ 2]  / answers: 1 / hits: 87969  / 12 Years ago, tue, may 22, 2012, 12:00:00

Right now, whenever I want to deploy a node.js server to my production server, I need to change all the IP/DNS/username/password for my various connection to my databases and external APIs.



This process is annoying, is there a way to verify if the currently running node.js instance is in cloud9ide or actually my production joyent smartmachine?



If I am able to detemrine (in my running code) on which server my node.js instance is running , I'll add a condition that set the values to the prod or dev.



Thank you


More From » node.js

 Answers
180

Normally you should run a node app in production like this:



NODE_ENV=production node app.js



Applications with Express, Socket.IO and other use process.env.NODE_ENV to figure out the environment.



In development you can omit that and just run the app normally with node app.js.



You can detect the environment in your code like this:



var env = process.env.NODE_ENV || 'development';
loadConfigFile(env + '.json', doStuff);


Resources:



How do you detect the environment in an express.js app?


[#85433] Monday, May 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;