Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the server name for where node.js is running?

Tags:

node.js

I want to add a line that will point to a different database depending on the server I am running node.js on (localhost vs test.com, etc). How do I get the server name in node.js? That is, what is the server side equivalent to location.host?

like image 765
Joel Avatar asked Dec 05 '14 20:12

Joel


2 Answers

var os = require('os');
os.hostname();

link

like image 89
Dmitry Matveev Avatar answered Sep 19 '22 15:09

Dmitry Matveev


req.headers.host #The request host.

You can refer to Node.js document here.

like image 40
Brady Huang Avatar answered Sep 19 '22 15:09

Brady Huang