Question

running live-server

I have node.js, npm, and live-server installed on my server:

# node -v
v20.5.1
# npm -v
9.8.0
# live-server -v
live-server 1.2.2

I want to connect to the live-server server remotely. In my firewall, I opened port 8080 for both incoming and outgoing. When I run live-server, I’m able to connect to the server remotely.

However, my local browser doesn’t get live updates when I update files. I don’t see any errors in Chrome or from live-sever, I just don’t get the updates.

How can I get those live updates?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
August 31, 2023

Live-server is built to provide instant updates to your local browser every time a file is updated in your server. If you’re not receiving those updates, it could be because the WebSocket connection that live-server uses is blocked or not functioning properly. You might need to ensure that your firewall allows WebSocket connections.

Besides, if your live-server instance is running inside a Docker container or behind a reverse proxy, you may need to make sure these configurations also allow WebSocket traffic.

Make sure to check your browser console for any potential errors related to WebSocket connections.

Hope that this helps!

KFSys
Site Moderator
Site Moderator badge
August 30, 2023

Heya,

When you run live-server on your remote server and connect to it with a local browser, the browser establishes a WebSocket connection back to the server for live-reloading. This WebSocket connection allows the server to send messages to the browser to trigger a page reload whenever files change.

The issue you’re encountering may be related to WebSockets not working correctly due to the following reasons:

  1. WebSocket Port: The WebSocket may be trying to use a different port than 8080, and this port might not be open on your firewall.

  2. WebSocket Origin Restrictions: There might be CORS (Cross-Origin Resource Sharing) or origin restrictions preventing the WebSocket connection from being established.

Here’s how you can diagnose and potentially fix these issues:

  1. Check the WebSocket Connection:

    • Open the Developer Tools in your browser (F12 or Ctrl+Shift+I / Cmd+Option+I).
    • Go to the Network tab.
    • Reload the page.
    • Filter by “WS” (which stands for WebSockets).
    • See if there’s a WebSocket connection. If it’s red or shows an error, you might get clues as to what’s going wrong.
  2. Allowing All Origins in live-server:

    To avoid potential WebSocket origin issues, try running live-server with the following command:

live-server --no-cors
  1. This disables CORS checks, which might solve the problem if it’s origin-related.

  2. Check Other WebSocket Ports:

    If WebSockets are not using port 8080, you need to figure out which port they are using and open it on your firewall.

  3. Use a Reverse Proxy:

    If you are familiar with tools like Nginx or Apache, you could set up a reverse proxy to handle the connection to the live-server. This way, you can ensure WebSockets work correctly, and you have more control over which ports are exposed and how traffic is routed.

  4. Check Console for Errors:

    Inspect the browser console for any error messages. Sometimes these errors can provide hints or direct explanations of what’s going wrong.

  5. Consider Using a Different Tool:

    If live-server continues to be problematic, you might consider other tools like BrowserSync, which can also handle live-reloading and might offer better configurability or clearer error messages.

Lastly, ensure you don’t have any browser extensions (like ad blockers or security extensions) that might be interfering with the WebSocket connections.

Bobby Iliev
Site Moderator
Site Moderator badge
August 29, 2023

Hi there,

This sounds like an issue with your host binding. By default, many local development servers bind to localhost or 127.0.0.1. This means they only accept connections from the same machine they are running on. You need to ensure live-server binds to 0.0.0.0. This means it will accept connections from any IP address.

You can do this using:

live-server --host=0.0.0.0

After that, along with your firewall rule, it will be able to accept connections as normal.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel