Eduardo Magaldi
Eduardo Magaldi

Reputation: 91

How can I check in which URL my node.js server is running?

I have two servers :

  1. db.mydomain.com and
  2. db2.mydomain.com (for development)

How can I check which server is my code running at?

I want to do a backup of my data from the production one but not from the dev one. Any ideas on how to do that?

Upvotes: 3

Views: 1184

Answers (1)

adeneo
adeneo

Reputation: 318172

You can get the hostname in any request

app.get('/', function(req, res) {
     var domain = req.headers.host;
     var parts  = domain.split(".");
     //assume www for no subdomain
     var subdomain = parts.length == 2 ? "www" : parts[0]; 
    ....
});

Upvotes: 2

Related Questions