Yes, it is possible with one of these NPM modules:
http-proxy-agent : HTTP proxy implementation of HTTP.Agent for HTTP endpoints
https-proxy-agent: HTTP-- HTTP.Agent HTTPS
pac-proxy-agent: - PAC HTTP.Agent HTTP HTTPS
socks-proxy-agent: - SOCKS (v4a) HTTP.Agent HTTP HTTPS
HTTPS:
var url = require('url');
var WebSocket = require('ws');
var HttpsProxyAgent = require('https-proxy-agent');
var proxy = process.env.http_proxy || 'http://168.63.76.32:3128';
console.log('using proxy server %j', proxy);
var endpoint = process.argv[2] || 'ws://echo.websocket.org';
var parsed = url.parse(endpoint);
console.log('attempting to connect to WebSocket %j', endpoint);
var opts = url.parse(proxy);
var agent = new HttpsProxyAgent(opts);
var socket = new WebSocket(endpoint, { agent: agent });
socket.on('open', function () {
console.log('"open" event!');
socket.send('hello world');
});
socket.on('message', function (data, flags) {
console.log('"message" event! %j %j', data, flags);
socket.close();
});
, .