tcp-local-tunnel
Expose localhost to the Internet using TCP sockets!
About
Simple module that allows to expose server from local network to the Internet. It works similarly to localtunnel, but is more stable and simpler.
I'm not providing a service where you can access your exposed local server, you will need to have some VPS or another machine connected to the internet with at least two open ports.
Module creates connection from your local server to your remote server via TCP and transmits data in both ways with established tunnel.
This is extremely useful when you need to access an IoT device (Raspberry PI i.e) running in your home network. For example you can turn off light (that you forgot to turn off, or just to make sure) in home from your workplace or any other place on Earth.
I'm also working on NodeMCU implementation of client side module (ESP8266 devices)
Module supports any protocol that uses TCP, eg. HTTP, Websocket.
The stability mostly depends on your local internet connection quality.
Security caveats
If somebody knows host and port of your remote server which local machine connects to, then he also can creates tunnel and redirect remote requests to his machine instead of yours.
Tunnel connection is not encrypted, so potential attacker can read data you are sending.
See alternatives for more secure solutions.
Basic-usage
npm install tcp-local-tunnel
Let's say your local server is listening on 3000
Code to run on local machine
const client = ;;
Code to run on remote machine
const proxyServer = ; ;
./example
)
Run server and expose it immediately (code in Code to run on local machine
const fs = ;const express = ;const bodyParser = ; const client = ; /* simple express server showcase */ const serverPort = 3000; const server = ; server;server; server;server;server;server; server; /* tcp tunnel config */ ;
Code to run on remote machine
const proxyServer = ; /* internet server proxy configuration */ ;
API
Client (local side)
const client = ; ;
ProxyServer (remote side)
const proxyServer =
Alternatives
You can use SSH remote port forwarding to achieve the same. It's encrypted and hence more secure.
See Remote Forwarding chapter https://www.ssh.com/ssh/tunneling/example
Contributing
Project is open to contributions, just rise an issue if you have some ideas about features or you noticed a bug. After discussion we can approach implementation :)
@jayu
Made with 🧠 byI hope that this small piece of software will help you build fancy IoT systems. If this tool was useful, don't hesitate to give it a 🌟!
License
MIT