Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Change the port where the Node.js server listens, restart the process supervisor that launches it, then verify the new socket locally and from the internet. The safest general pattern is to keep the value outside your source code:

const port = Number(process.env.PORT || 3000);
app.listen(port, '127.0.0.1', () => {
  console.log(`Listening on ${port}`);
});

For a public Node listener, expose the selected TCP port through both the VPS provider’s firewall and the guest operating system firewall. If NGINX is the public endpoint, leave Node on a private address and update NGINX’s upstream instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What actually changes when you change a Node.js port?

A port is part of the socket address on which your application accepts TCP connections. Changing a DNS record or editing a browser URL does not move that listener. The Node process must start again with a different port value, and every component between the client and the process must agree with the change.

Node exposes this through server.listen([port[, host[, backlog]]][, callback]), the TCP listening API documented in the Node.js net documentation. Express’s app.listen() is the same operation as Node’s http.Server.listen(), with a port and optional host, as described in the Express application API.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

If you omit the port or pass 0, the operating system chooses an unused port. That is useful for tests, but it is normally unsuitable for a VPS service that clients or a reverse proxy must reach at a known address. If you omit the host, Node uses the unspecified IPv6 address when available or the unspecified IPv4 address otherwise, so set the host deliberately when exposure matters.

Choose the VPS network design before editing code

There are two valid ways to expose a Node application. Decide which one you use before changing firewall and proxy settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Design Node bind Public connection Firewall responsibility Typical reason to choose it
Direct Node exposure An externally reachable interface, such as the VPS address or an appropriate wildcard address Clients connect to the selected Node port directly Permit the selected TCP port in the provider firewall and the guest OS firewall A simple service where Node itself is the public HTTP endpoint
NGINX reverse proxy A private address such as 127.0.0.1 and the new internal port Clients connect to NGINX on the public HTTP or HTTPS port Permit the proxy’s public ports; keep the Node port private TLS termination, hostname routing, centralized logs, or multiple applications

The official NGINX Node.js deployment guide describes the reverse-proxy and load-balancing pattern. A private bind is not a defect in that design: it prevents arbitrary internet clients from bypassing the proxy.

Step 1: Find where the port is configured

Start with the entry point and the files used by the process supervisor. Search for the listener and for environment names:

  • app.listen(
  • server.listen(
  • PORT or NODE_PORT
  • A framework-specific server or port setting

Look beyond the main JavaScript file. The value may come from a systemd unit, an environment file, a process-manager definition, a container configuration, or a hosting control panel. The goal is to identify the value supplied to listen(), not merely a URL displayed in the application.

Prefer an environment-driven expression so one build can run on development, staging, and production ports:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const port = Number(process.env.PORT || 3000);
const host = process.env.HOST || '127.0.0.1';

app.listen(port, host, () => {
  console.log(`Listening on ${host}:${port}`);
});

process.env is Node’s process-environment object, documented in the Node.js process documentation. Validate the value if your application needs stricter behavior; an invalid or unexpectedly empty value should fail clearly rather than silently selecting the wrong endpoint.

Step 2: Set the new runtime value

For a process started from a shell

Supply the value on the same command that starts Node:

PORT=8080 node server.js

This assignment applies to that process only. Closing the shell or starting the application through a different supervisor will not carry the setting over automatically. For a temporary test, you can use another value without changing source files:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
PORT=8080 node app.js

When the program starts, its log should identify the new port. If it still reports 3000, you are either launching a different entry point, overriding PORT later, or running an older process.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For systemd

Put the value in the unit that actually launches the application. A minimal pattern is:

[Unit]
Description=Node application
After=network.target

[Service]
Type=simple
User=nodeapp
WorkingDirectory=/srv/my-app
Environment=NODE_ENV=production
Environment=PORT=8080
ExecStart=/usr/bin/node /srv/my-app/server.js
Restart=always

[Install]
WantedBy=multi-user.target

You can keep deployment-specific values in a separate file instead:

[Service]
EnvironmentFile=/etc/my-app/my-app.env

With /etc/my-app/my-app.env containing:

PORT=8080

After editing a unit file, reload systemd’s unit definitions, then restart the service:

sudo systemctl daemon-reload
sudo systemctl restart my-app.service
sudo systemctl status my-app.service

If you changed only the referenced environment file, restarting the unit is still required. A running process receives a snapshot of its environment when it is created; editing a file does not mutate that process. Express’s production guidance recommends an init system for recovery after crashes and host restarts and shows systemd units with ExecStart, WorkingDirectory, Environment, and Restart=always; see the Express production guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For containers or another process supervisor

Change the environment setting in the supervisor’s definition, recreate the container or managed process, and verify that the new instance—not an old one—is serving traffic. A restart command that merely reloads application code may not replace the process environment. The exact control-panel or supervisor command varies, but the sequence is always the same: update the definition, recreate the process, inspect its logs, and check the listening socket.

Step 3: Bind Node to the correct host

The port number and bind address are separate decisions. For a reverse proxy, use a private address:

const port = Number(process.env.PORT || 8080);
app.listen(port, '127.0.0.1', () => {
  console.log(`Listening on ${port}`);
});

Only software on the VPS can reach a loopback listener. NGINX can connect to 127.0.0.1:8080, while an internet client cannot connect directly to that port.

For direct exposure, bind to the interface required by your VPS design and make sure the selected address is reachable from the client network. A wildcard address can listen on all suitable interfaces, but it also increases the interfaces on which the service is exposed. Choose deliberately, especially when the VPS has both public and private interfaces.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Changing only the host while leaving a firewall or proxy pointed at the old port produces the same symptoms as a failed port change. Treat host, port, proxy target, and firewall rules as one configuration.

Step 4: Restart the process that owns the application

Restart the actual supervisor, not just a terminal command that is unrelated to production. Common ownership patterns include:

  • A systemd unit: sudo systemctl restart my-app.service
  • A container: recreate or restart the container after changing its environment
  • A process manager: restart the named application through that manager
  • A hosting control panel: use the panel’s application restart or redeploy action

Immediately inspect the startup output. For systemd, use:

sudo journalctl -u my-app.service -n 100 --no-pager

Look for the expected “Listening on” message and for startup errors. If the old process still owns the old port, the supervisor may have failed to stop it, or another service may be using it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 5: Align provider and operating-system firewalls

A direct listener is reachable only when every relevant network policy permits it. Open the new TCP port in the VPS provider’s firewall or security group and in the guest operating system firewall. These controls are commonly separate; changing one does not automatically change the other.

For a system using UFW, an example rule for port 8080 is:

sudo ufw allow 8080/tcp
sudo ufw status

Use the port selected for your service and follow your organization’s source-address restrictions where possible. Remove an obsolete direct-exposure rule only after you have confirmed that no service or operational procedure still depends on it.

With NGINX as the public endpoint, allow the public HTTP and HTTPS ports required by your site and keep the Node port private. Do not expose the internal port merely because it is convenient for troubleshooting; test it from the VPS itself instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 6: Update NGINX when it proxies to Node

If NGINX forwards requests to the application, its upstream target must match Node’s new host and port exactly. For example, if Node now listens on loopback port 8080:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Test the configuration before reloading it, then reload NGINX:

sudo nginx -t
sudo systemctl reload nginx

A reload applies the upstream change without unnecessarily stopping the web server. If you use an upstream block or several application instances, update every target that should receive traffic. Inspect both NGINX’s error log and the Node service log when requests fail.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 7: Verify the new listener in layers

Verification should proceed from the process outward. Each layer rules out a different class of failure.

  1. Read the application log. Confirm that the running process reports the intended host and port, not merely that a deployment command completed.
  2. Inspect listening sockets. On a Linux VPS, use the socket utility available on the system, commonly ss:
sudo ss -ltnp | grep 8080

The output should show a listening TCP socket owned by the expected Node process. If the service is bound to 127.0.0.1:8080, that is correct for a reverse-proxy design but not for direct internet access.

  1. Request the application locally. Test the bind independently of external firewalls:
curl -i http://127.0.0.1:8080/

Use the correct path and scheme for your application. A successful response proves that something on the VPS can reach Node; it does not prove that NGINX, a provider firewall, or a public route is correct.

  1. Test through the proxy, if present. Request the public hostname over the scheme and port exposed by NGINX:
curl -i http://example.com/

For HTTPS, use the site’s HTTPS URL. A 502 or 504 at this stage usually indicates an upstream mismatch or an unavailable Node process, whereas a timeout points more often to filtering or routing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Test direct access only when intended. From a machine outside the VPS, connect to the public IP and selected port. Do not interpret a failed direct test as a problem when Node is intentionally private behind NGINX.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot the common failure modes

The app still uses port 3000

  • The process was not recreated after changing the environment.
  • The supervisor has its own PORT value that overrides the shell or .env file.
  • You edited one unit or container definition but restarted another.
  • The application falls back to 3000 because the variable name is wrong or unavailable to the service user.
  • A second copy of the application is the one receiving requests.

Check the supervisor’s effective configuration, restart it, read the new startup log, and inspect the owning PID with ss. Do not rely on the file you edited as proof of what the running process received.

EADDRINUSE appears during startup

EADDRINUSE means another process already owns the requested port or path. Node identifies this as the common error when a server attempts to listen on an address that is already in use; see the Node.js net documentation. Find the owner:

sudo ss -ltnp | grep 8080

Then stop or reconfigure the unintended listener, or choose a free port and update every dependent component. Avoid killing a process blindly on a production VPS: first establish which service owns it and whether it is the intended application.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Local requests are refused

The process may have crashed, failed to restart, be listening on a different port, or be bound to a different address family. Check service status and recent logs, confirm the socket with ss, and test the exact host and port shown by the listener. A private bind can also make a request to the VPS’s public IP fail while a request to 127.0.0.1 succeeds.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Internet requests time out

Confirm the provider firewall or security group, the guest OS firewall, routing, and the bind address. A successful local bind proves only that the kernel accepted the listener. It says nothing about whether an upstream network policy forwards traffic to that port.

NGINX returns 502 or 504

Compare NGINX’s upstream target character for character with Node’s actual host and port. Test the target locally from the VPS, check that the Node process is running, then run nginx -t and reload NGINX after correcting the configuration. Inspect both NGINX and application logs; a stale upstream port is a frequent cause immediately after a port change.

It works in an interactive shell but not under systemd

Interactive shells and systemd can have different users, working directories, PATH values, and environments. Put PORT=... in the unit’s Environment line or referenced environment file, use absolute paths in ExecStart, and restart the unit after editing. Verify the effective service logs rather than comparing it with a manually launched process.

Operational and security checks after the change

  • Record the new port and whether it is public or private.
  • Confirm the application logs the intended host and port at every startup.
  • Keep the same port in the supervisor, proxy configuration, health checks, deployment scripts, and monitoring probes.
  • For direct exposure, verify both provider and guest firewall rules from an external network.
  • For a reverse proxy, confirm that Node is reachable from NGINX but not unnecessarily exposed to the internet.
  • Remove obsolete firewall and proxy entries only after successful validation and a rollback plan.
  • Keep the supervisor configured to restart the application after a crash or host reboot.

There is no inherent performance improvement or degradation established simply by selecting a different listening port. The practical effects come from the surrounding design: exposure, proxying, firewall policy, and whether the new process was actually restarted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently asked questions

Can I change the port by changing DNS?

No. DNS resolves a name to an address; it does not move a process’s listening socket. The application or reverse proxy must listen on the desired port, and clients must use that port unless a standard public endpoint forwards to it.

Why does a browser omit the port from my URL?

HTTP and HTTPS normally use their standard public ports, so a reverse proxy can accept those requests and forward internally to any private Node port. If Node itself is the public endpoint on a nonstandard port, include that port in the URL.

Is port 0 a suitable production setting?

Usually not. Node passes 0 to the operating system, which selects an unused port. That is useful when a test needs an ephemeral listener, but a fixed service, firewall rule, proxy, and health check need a predictable destination.

Do I need to open the new port in UFW when NGINX is in front?

Not for public clients when Node is bound to loopback and NGINX is the only public entry point. Allow the public proxy ports and keep the internal Node port private; open an internal port only when another trusted component genuinely needs to reach it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

What is the fastest way to confirm which process owns a Node port?

Run sudo ss -ltnp | grep PORT on the VPS, replacing PORT with the number. The result identifies the listening socket and, when permitted, the owning process.

Should the new Node port be the same as the public website port?

No. With a reverse proxy, NGINX can keep public HTTP or HTTPS ports while forwarding to any private Node port. Only a directly exposed Node service needs clients to connect to its selected public port.

The Bottom Line

Changing a Node.js port is a coordinated deployment change: set process.env.PORT, bind to the intended interface, restart the real supervisor, align firewalls and any NGINX upstream, then verify the socket locally and through the public path.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.