node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



NPM version Dependencies Status

A Node.js tools that give the ability to execute JavaScript code in one client browser and to get the results in another. Based on HTTP (for static files and sync post requests) and WebSocket (for server-host communications) technologies. Supports CommonJS modules and can be used with Webpack or Browserify on the client-side.

Scheme to illustrate base working principles: scheme


npm install code-proxy


Start as a standalone server:

node server/main.js

Connect to an existing project:

// or it's possible to redefine default options 
    portHttp:   8800,
    portWs:     8900,
    retryDelay: 100,
    retryLimit: 30,
    logging:    true


Host client (accepts requests, execute them and send back result of execution):

<script type="text/javascript" src="host.js"></script>
// default host/port/session 
var proxy = new ProxyHost();
// prepare for guest call 
localStorage.setItem('test', 'localStorage test string on the host');
// test func for remote exec 
function doSomething ( param ) {
    return 'some host work with "' + param + '" is done';

Guest client (send requests to the host):

<script type="text/javascript" src="guest.js"></script>
// default host/port/session 
var proxy = new ProxyGuest();
// examples 
proxy.json('screen');'localStorage.getItem', ['test'], 'localStorage');'doSomething', ['test data']);

Proxy server host/port and session name can be redefined on both host and guest:

var proxy = new ProxyGuest({
    host: '',
    port: 8800,
    name: 'anonymous'

Both host and guest proxy instance have active boolean flag to determine the current connection to the proxy server status.

ProxyHost has some additional options: reconnect and reconnectInterval to automatically try to restore connection on disconnect every 5 seconds. It's active be default.