2

im new with node and a have a problem with express, my app only listen to localhost:PORT and i wanna to the app listen to localhost too, heres is my code,

**

var app = require('../app');
var debug = require('debug')('App');
var http = require('http');

var port = normalizePort(process.env.PORT || '8000');
app.set('port', port);

var server = http.createServer(app);

server.listen(port, 'localhost');
server.on('error', onError);
server.on('listening', onListening);

**

John
  • 483
  • 3
  • 9
  • 18
  • 1
    see [http://stackoverflow.com/questions/9526500/node-js-how-can-i-remove-the-port-from-the-url](http://stackoverflow.com/questions/9526500/node-js-how-can-i-remove-the-port-from-the-url) – Jérôme Jun 16 '16 at 12:02
  • thanks is this what im looking for – John Jun 16 '16 at 20:45

1 Answers1

2

You cannot listen without a port, because that would not make any sense. Every TCP connection needs to happen over some port. What you are looking for is the default 80 port for http, or 443 for https. The browser uses these ports by default.

Depending on the configuration of your system, a user space program may not necessarily have access to these ports. So you may have to configure your system to grant your node application access.

Kazimieras
  • 607
  • 4
  • 14