How to Use Mobile Proxies with Node.js
Node.js can send requests through an HTTP proxy with the ProxyAgent class of the undici package. The example below builds the login header, makes one request and prints the address the server sees.
What do I need before I start?
| Host | gw.mobileproxy.live |
|---|---|
| HTTP and HTTPS port | 9000 |
| SOCKS5 port | 9100 |
| Username | mp4x9q2.mobile.us.sid-a1b2.rot-10 |
| Password | YOUR_PASSWORD (your own line password) |
- Node.js 18 or newer
- The undici package (npm install undici)
- Your username and password in your account under My lines. The username above is an example, and each part is explained in the username reference.
How do I set it up?
- Create a project folder and run npm init -y, then npm install undici.
- Save the code below as check-ip.mjs so Node treats it as an ES module.
- Replace YOUR_PASSWORD with your own password.
- Run node check-ip.mjs. The JSON that prints should carry your line address and country.
- Create the ProxyAgent once and reuse it for every request in your program.
- Add error handling with a retry and a short delay between attempts.
What does the code look like?
import { fetch, ProxyAgent } from "undici";
const token = "Basic " + Buffer.from("mp4x9q2.mobile.us.sid-a1b2.rot-10:YOUR_PASSWORD").toString("base64");
const dispatcher = new ProxyAgent({ uri: "http://gw.mobileproxy.live:9000", token });
const res = await fetch("https://ipinfo.io/json", { dispatcher });
console.log(await res.json());How do I check my IP?
The printed object comes from https://ipinfo.io/json. Its ip and country should match the line. Remove the dispatcher option to see your own address.
https://ipinfo.io/json
On a mobile line you can ask for a fresh address at any time with your change-IP link, for example https://gw.mobileproxy.live/rotate/k7Qm2xV9. The real link for each line is in your account.
What if it does not work?
Error 407 from the proxy.
The login header is wrong. Confirm the username from your account and that the password has no stray characters.
Cannot use import outside a module.
Save the file with the .mjs extension, or set "type": "module" in package.json.
The built in fetch ignores the proxy.
Import fetch from undici as shown, so the dispatcher option is understood by the same library.
Frequently asked questions
Can I use axios instead?
Yes. Pair axios with the https-proxy-agent package and give it the same proxy URL with the login.
How do I rotate the IP?
Open the change IP link from your account between requests, or let the timer in the username change it for you.
Does this support SOCKS5?
Use a SOCKS agent package for that. For most work the HTTP port is the simpler choice.
Related guides
Need a line to connect?
Create an account, top up your balance and your first line is ready to use with Node.js.