Home > Software engineering >  Can't access npm application from other device on the network
Can't access npm application from other device on the network

Time:01-25

I have just developed a node application. If I execute this command

npm run start

the application starts and I can access it at this address

http://localhost:8080/

The problem is that I want to access the application from my cellphone that is connected to the same wifi network as my PC. Therefore I have launched the ipconfig command on my PC and found out that in the section titled "Wireless LAN adapter Wi-Fi" the value of "IPv4 Address" is "192.168.x.y". So I opened the browser in my cellphone and typed the address

http://192.168.x.y:8080/

but nothing is displayed. Do I need to use Apache?

CodePudding user response:

You might have to check if your firewall is opened on the port you are trying to access

CodePudding user response:

The solution was to use Apache. The procedure is the following:

  1. Install XAMPP
  2. Go to the directory of the application and launch the command "npm run build". The resulting files will be saved in the "dist" directory. Among these files there should be a file called "index.html".
  3. Copy the content of the "dist" directory into the "htdocs" directory located inside the XAMPP directory.
  4. Start Apache through the XAMPP Control Panel.

Now it is possible to access the website locally through the "localhost" address. To access the website from another device you must use the ip address of the device where the website is deployed (that is your PC). In order to know the ip address of your PC launch the "ipconfig" command. The ip address of your PC is the value of the "IPv4 Address" property of the "Wireless LAN adapter Wi-Fi" section. You don't need to type the port, only the ip address.

  •  Tags:  
  • npm
  • Related