Reputation: 517
My code is like this
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var rq=require('request');
var url="http://localhost/ss/some.json";
var pages=Object();
rq(url, function (error, response, body) {
pages=JSON.parse(body);
});
here var url="http://localhost/ss/some.json";
i want to get "localhost" without sending any request
i tried
require("os").hostname();;
but this is returning machine name
Upvotes: 3
Views: 1905
Reputation: 412
You can't get the hostname your service listens to unless you explicitely define it (in configuration) or wait for the request to pull it from there.
The hostname of the machine hosting your service is probably not the hostname your service listens to from the outside.
Upvotes: 1