umma.dev

Setting Up a NodeJS Proxy

A proxy can has a number of different use cases. Here I discuss how to set up a NodeJS proxy.

What is a Proxy?

A proxy enables you to create a connection between two different elements. For example, you may have a ReactJS user interface and a Python/Java back-end. In order to be able to get the data from the back-end to the front-end, the best way to do this is via a proxy.

Example Code

const net = require('net');
const server = net.createServer();

server.on('connection', (clientToProxySocket) =\> {
 console.log('Client Connected To Proxy');
});

server.on('error', (err) =\> {
 console.log('SERVER ERROR');
 console.log(err);
});

server.on('close', () =\> {
 console.log('Client Disconnected');
});

server.listen(8124, () =\> {
 console.log('Server runnig at [http://localhost:'](http://localhost:') + 8124);
});