Localhost doesn't launch when triggered by nodeJS | Sololearn: Learn to code for FREE!

+2

Localhost doesn't launch when triggered by nodeJS

I have a Wamp server on windows & I have installed visual studio code for running nodejs programs. As first step m trying to run a sample program which will display an HTML page. But the issue is, localhost refuses to connect. As checked, currently the port set in httpd.conf is set to 80 & if launch directly localhost does open on this port. But when I try to do d same through nodejs it just doesn't launch it. Can anyone help regarding this issue. Thanks in advance for your support!

8/4/2021 6:00:59 PM

Shweta Gare

1 Answer

New Answer

+2

localhost is the loopback connection. It does not even need a network interface. The IP address for localhost is typically 127.0.0.1 You don't launch localhost. You launch your web server and configure it to listen to the localhost IP and required port number. Multiple servers can use the same IP address if listening to different ports. By default when httpd starts, it binds to some port and address on the local machine and waits for incoming requests. By default, it listens to all addresses on the machine. So it should already be listening to port 80 on the loopback address. I have no idea what you are referring to by launching localhost through node.js since you can't launch localhost, it simply exists, your application is supposed to bind itself to the address. If the application does not have elevated rights the OS may not permit it to bind to a port below 1024. Note also that your node application will not bind to port 80 if it is already reserved for httpd. Using the Visual Studio IDE with Node and the Internet Information Server Express Edition (IIS Express) the server will usually bind itself to a higher numbered port to allow a test server to be run by developers without requiring admin rights.