We need to expose our local Node.js + Express backend (with LangChain integration) to the public using a stable, long-running, and free solution.
The goal is to allow external users, collaborators, or client applications to access the AI backend without requiring local setup, VPN, or port forwarding.
✅ Chosen Solution
-
Cloudflare Tunnel (cloudflared)
Used for public HTTPS exposure of the local server, enabling secure and reliable access over the internet.
-
PM2 Process Manager
Runs both the backend server and the Cloudflare tunnel in the background, ensuring they stay up and restart automatically if needed.
🔧 Setup & Configuration Tasks
To expose the backend using Cloudflare Tunnel and manage processes with PM2, follow these steps:
1. Install and Configure Cloudflared CLI
- Download and install the
cloudflared CLI from Cloudflare's official site.
- Authenticate and create your tunnel according to their documentation.
2. Update Project Scripts or Documentation
- Ensure your project scripts support starting both the backend and tunnel easily.
- Example tunnel command:
cloudflared tunnel --url http://localhost:<PORT>
3. Use PM2 to Run Both Services
- Run your Node.js backend (e.g., server.js) with PM2:
pm2 start server.js --name backend
- Run the Cloudflare tunnel with PM2:
pm2 start "cloudflared tunnel --url http://localhost:<PORT>" --name tunnel
- Make sure the tunnel URL is displayed or logged on startup for easy reference.
4. Keep Services Running After Reboot
- Use PM2 startup script to launch services on system boot: