Node.js Legacy Tunnel Proxy: phantomjs / casperjs / request
Deprecated but still widely deployed Node.js tools integrating 16Yun Crawler Proxy.
16Yun Engineering TeamApr 21, 20261 min read
phantomjs
PhantomJS is archived but still widely used in legacy projects. Configure via --proxy and --proxy-auth:
// main.js — Launch phantomjs via child process
const { spawn } = require('child_process');
const path = require('path');
const host = process.env.PROXY_HOST || 't.16yun.cn';
const port = process.env.PROXY_PORT || '31111';
const user = process.env.PROXY_USERNAME || 'user';
const pass = process.env.PROXY_PASSWORD || 'password';
const target = process.env.TARGET_URL || 'https://httpbin.org/ip';
const child = spawn('phantomjs', [
`--proxy=${host}:${port}`,
`--proxy-auth=${user}:${pass}`,
'http-demo.js', target,
], { stdio: 'inherit' });// http-demo.js — PhantomJS page script
var page = require('webpage').create();
var system = require('system');
var target = system.args[1] || 'https://httpbin.org/ip';
page.open(target, function(status) {
if (status === 'success') {
console.log(page.plainText);
}
phantom.exit();
});casperjs
CasperJS builds on PhantomJS, using the --proxy parameter:
casperjs --proxy=http://t.16yun.cn:31111 \
--proxy-auth=user:pass \
main.jsvar casper = require('casper').create();
var target = 'https://httpbin.org/ip';
casper.start(target, function() {
this.echo(this.getPageContent());
});
casper.run();request
The request library is deprecated, but massive legacy codebases still exist:
const request = require('request');
const host = process.env.PROXY_HOST || 't.16yun.cn';
const port = process.env.PROXY_PORT || '31111';
request({
url: 'https://httpbin.org/ip',
proxy: `http://${user}:${pass}@${host}:${port}`,
headers: { 'Proxy-Tunnel': process.env.PROXY_TUNNEL || 'request-demo' },
timeout: 15000,
}, (err, resp, body) => {
if (!err) console.log(body);
});Migration Recommendations
| Tool | Status | Recommended Replacement |
|---|---|---|
| PhantomJS | Archived in 2023, unmaintained | Puppeteer / Playwright |
| CasperJS | Discontinued with PhantomJS | Playwright / Puppeteer |
| request | Deprecated in 2020 | undici / got / axios |
Need an enterprise proxy plan?
We can tailor architecture to your target domains, concurrency, and reliability goals.