When you run a web server on your machine at 127.0.0.1:3000, it's only accessible from that same computer. This is by design - localhost (127.0.0.1) is a loopback address that never leaves your machine. To make it accessible to other devices on your network, you need to expose it through your machine's actual IP address.
First, determine your computer's local network IP address. This varies by OS:
On macOS/Linux:
ifconfig | grep "inet " | grep -v 127.0.0.1
On Windows:
ipconfig | findstr "IPv4"
You'll get output like 192.168.1.12
- this is what you'll use instead of 127.0.0.1 from other devices.
Most development servers (like create-react-app, Next.js, etc.) default to binding to localhost only. You'll need to configure them to accept external connections:
Node.js/Express Example:
const express = require('express');
const app = express();
const port = 3000;
app.listen(port, '0.0.0.0', () => {
console.log(Server running at http://0.0.0.0:${port}/);
});
The key is '0.0.0.0'
which makes it listen on all network interfaces.
React (create-react-app):
HOST=0.0.0.0 npm start
Next.js:
next dev -H 0.0.0.0
Vue CLI:
vue-cli-service serve --host 0.0.0.0
From your iPhone or another device:
- Ensure both devices are on the same WiFi network
- Open browser and enter your computer's IP with port:
http://192.168.1.12:3000
If it doesn't work:
- Check your firewall settings (may need to allow port 3000)
- Verify both devices are on the same network
- Try pinging your computer's IP from the other device
To access your localhost from anywhere (even different networks), use ngrok:
ngrok http 3000
This creates a public URL that tunnels to your localhost.
When you run a web server on your local machine (like Node.js, Flask, or Django), it typically binds to 127.0.0.1
by default. This means it's only accessible from your own computer. To make it available to other devices on your network, you need to expose it properly.
First, determine your computer's local IP address:
# On macOS/Linux:
ifconfig | grep "inet "
# On Windows:
ipconfig
Look for an address like 192.168.x.x
or 10.x.x.x
(not 127.0.0.1
).
Most frameworks allow you to specify the host parameter:
// Node.js Express example
const express = require('express');
const app = express();
const PORT = 3000;
app.listen(PORT, '0.0.0.0', () => {
console.log(Server running at http://YOUR_LOCAL_IP:${PORT});
});
# Python Flask example
from flask import Flask
app = Flask(__name__)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000)
On your iPhone or other device, simply navigate to:
http://YOUR_LOCAL_IP:3000
Replace YOUR_LOCAL_IP
with the address you found earlier.
If you can't connect, check these:
- Firewall settings (allow incoming connections on port 3000)
- The server is actually running (
netstat -ano | findstr 3000
on Windows) - Both devices are on the same network
If you need access beyond your local network:
# Install ngrok (https://ngrok.com/)
./ngrok http 3000
This will give you a public URL that tunnels to your localhost.