# NPort > ๐Ÿš€ Free & open source ngrok alternative - Tunnel localhost to the internet via Cloudflare Edge [![GitHub](https://img.shields.io/github/stars/tuanngocptn/nport?style=social)](https://github.com/tuanngocptn/nport) [![NPM](https://img.shields.io/npm/v/nport?color=red&logo=npm)](https://www.npmjs.com/package/nport) [![Website](https://img.shields.io/website?url=https%3A%2F%2Fnport.link&up_message=nport.link&up_color=blue&down_color=lightgrey&down_message=offline)](https://nport.link) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue.svg)](https://www.typescriptlang.org/) ## What is NPort? [![nport](https://github.com/user-attachments/assets/809634a9-5396-46da-919d-b642ddf48fd1)](https://nport.link) NPort is a powerful, lightweight **ngrok alternative** that creates secure HTTP/HTTPS tunnels from your localhost to public URLs using **Cloudflare's global edge network**. No configuration, no accounts, just instant tunnels with custom subdomains! Perfect for: - ๐Ÿš€ **Development environments** - Share your local work instantly - ๐Ÿ”’ **Testing webhooks** - Receive webhooks from GitHub, Stripe, PayPal, etc. - ๐Ÿ“ฑ **Mobile testing** - Test your web app on real devices - ๐Ÿ› ๏ธ **API development** - Debug integrations with external services - ๐Ÿ‘ฅ **Demo to clients** - Show your progress without deployment ## โœจ Features - โšก **Instant Setup**: One command to expose your localhost - ๐ŸŒ **Custom Subdomains**: Choose your own URL (e.g., `myapp.nport.link`) - ๐Ÿ”’ **Automatic HTTPS**: SSL/TLS encryption via Cloudflare - ๐ŸŒ **Global Edge Network**: Fast connections worldwide via Cloudflare - ๐Ÿ“ก **WebSocket Support**: Full WebSocket and Server-Sent Events support - ๐ŸŽฏ **No Configuration**: Works out of the box - ๐Ÿ’ป **Cross-Platform**: Windows, macOS, and Linux support - ๐Ÿ—ฃ๏ธ **Multilingual**: English, Vietnamese and Spanish UI support - ๐Ÿ†“ **100% Free**: No accounts, no limits, no paywalls - ๐Ÿ”“ **Open Source**: MIT licensed ## ๐Ÿ“ฆ Installation ### Requirements - **Node.js** >= 20.0.0 - **npm** >= 10.0.0 Check your versions: ```bash node --version npm --version ``` ### NPM (Recommended) ```bash # Global installation npm install -g nport # Or use npx without installation npx nport 3000 -s myapp ``` ### From GitHub ```bash npm install -g git+https://github.com/tuanngocptn/nport.git ``` ## ๐Ÿš€ Quick Start ### Basic Usage Expose port 3000 with a random subdomain: ```bash nport 3000 ``` Output: ``` โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚ N P O R T โšก๏ธ Free & Open Source from Vietnam โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ โ ‹ Creating tunnel for port 3000... ๐Ÿš€ WE LIVE BABY! ๐Ÿ‘‰ https://user-1234.nport.link ๐Ÿ‘ˆ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โฑ๏ธ Time: 4h remaining โœ” [1/2] Connection established... โœ” [2/2] Compression enabled... โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿ”ฅ KEEP THE VIBE ALIVE? (Made with โค๏ธ in Vietnam) โญ๏ธ Drop a Star: https://github.com/tuanngocptn/nport โ˜•๏ธ Buy Coffee: https://buymeacoffee.com/tuanngocptn ``` ### Custom Subdomain Choose your own subdomain: ```bash nport 3000 -s myapp # Creates: https://myapp.nport.link ``` Or using long form: ```bash nport 3000 --subdomain myapp ``` ## ๐Ÿ“– Usage Examples ### Web Development ```bash # Next.js npm run dev nport 3000 -s my-nextjs-app # React (Create React App) npm start nport 3000 -s my-react-app # Vue.js npm run dev nport 8080 -s my-vue-app # Express.js node server.js nport 3000 -s my-api ``` ### Webhook Testing ```bash # Start your local webhook receiver node webhook-receiver.js # Expose it to the internet nport 4000 -s my-webhooks # Use in GitHub webhook settings: # https://my-webhooks.nport.link/webhook ``` ### Mobile Device Testing ```bash # Start your local dev server npm run dev # Create tunnel nport 3000 -s mobile-test # Open on your phone: # https://mobile-test.nport.link ``` ## ๐ŸŽฏ CLI Options ```bash nport [options] ``` | Option | Short | Description | Example | |--------|-------|-------------|---------| | `` | - | Local port to tunnel (default: 8080) | `nport 3000` | | `--subdomain` | `-s` | Custom subdomain | `nport 3000 -s myapp` | | `--backend` | `-b` | Custom backend URL (temporary) | `nport 3000 -b https://your-backend.com` | | `--set-backend` | - | Save backend URL permanently | `nport --set-backend https://your-backend.com` | | `--language` | `-l` | Set language (en/vi/es) or prompt | `nport 3000 -l es` | | `--version` | `-v` | Show version information | `nport -v` | ### Language Options NPort supports multiple languages with automatic detection on first run. ```bash # Set language directly nport 3000 --language en # English nport 3000 -l vi # Vietnamese nport 3000 -l es # Espaรฑol # Open language selection menu nport --language # Interactive prompt nport -l # Interactive prompt ``` On first run or when using `--language` without a value, you'll see an interactive language picker. Your choice is automatically saved for future sessions. ### Backend URL Options NPort uses a default backend at `https://api.nport.link`, but you can use your own backend server. #### Temporary Backend (One-time Use) Use a custom backend for just the current session: ```bash # Use custom backend via CLI flag nport 3000 --backend https://your-backend.com nport 3000 -b https://your-backend.com # Use custom backend via environment variable export NPORT_BACKEND_URL=https://your-backend.com nport 3000 # Combine with other options nport 3000 -s myapp -b https://your-backend.com ``` #### Persistent Backend (Saved Configuration) Save a backend URL to use automatically in all future sessions: ```bash # Save backend URL permanently nport --set-backend https://your-backend.com # Now all future commands will use this backend nport 3000 # Uses saved backend nport 3000 -s myapp # Uses saved backend # Clear saved backend (return to default) nport --set-backend # Override saved backend temporarily nport 3000 -b https://different-backend.com ``` **Configuration Priority:** 1. CLI flag (`--backend` or `-b`) - Highest priority 2. Saved config (`--set-backend`) 3. Environment variable (`NPORT_BACKEND_URL`) 4. Default (`https://api.nport.link`) - Lowest priority **Configuration Storage:** Your backend preference is saved in `~/.nport/config.json` This is useful if you want to: - **Self-host**: Run your own NPort backend (see [server/](server/) directory) - **Development**: Test against a local backend - **Custom domains**: Use your own domain for tunnel URLs - **Enterprise**: Use a company-hosted backend server ### Version Information ```bash # Check current version and updates nport -v nport --version ``` ## ๐Ÿ”ง How It Works 1. **You run** `nport 3000 -s myapp` 2. **NPort creates** a Cloudflare Tunnel 3. **DNS record** is created: `myapp.nport.link` โ†’ Cloudflare Edge 4. **Cloudflared binary** connects your localhost:3000 to Cloudflare 5. **Traffic flows** through Cloudflare's global network to your machine 6. **On exit** (Ctrl+C), tunnel and DNS are automatically cleaned up ``` Internet โ†’ Cloudflare Edge โ†’ Cloudflare Tunnel โ†’ Your localhost:3000 (https://myapp.nport.link) ``` ## ๐Ÿ—๏ธ Project Structure ``` nport/ โ”œโ”€โ”€ src/ # TypeScript source files โ”‚ โ”œโ”€โ”€ index.ts # Entry point โ”‚ โ”œโ”€โ”€ tunnel.ts # Tunnel orchestration โ”‚ โ”œโ”€โ”€ api.ts # Backend API client โ”‚ โ”œโ”€โ”€ args.ts # CLI argument parser โ”‚ โ”œโ”€โ”€ binary.ts # Cloudflared process manager โ”‚ โ”œโ”€โ”€ ui.ts # Console UI components โ”‚ โ”œโ”€โ”€ lang.ts # Multilingual support โ”‚ โ”œโ”€โ”€ types/ # TypeScript type definitions โ”‚ โ””โ”€โ”€ ... โ”‚ โ”œโ”€โ”€ tests/ # Unit tests (vitest) โ”œโ”€โ”€ dist/ # Compiled output โ”œโ”€โ”€ bin/ # cloudflared binary (downloaded) โ”‚ โ”œโ”€โ”€ server/ # Backend (Cloudflare Worker) โ”œโ”€โ”€ website/ # Static landing page โ”œโ”€โ”€ docs/ # Documentation โ”‚ โ”œโ”€โ”€ ARCHITECTURE.md # Technical architecture โ”‚ โ”œโ”€โ”€ API.md # API reference โ”‚ โ””โ”€โ”€ CONTRIBUTING.md # Contribution guide โ””โ”€โ”€ .ai/ # AI context files ``` ## ๐Ÿ›ก๏ธ Security - **HTTPS by default**: All tunnels use SSL/TLS encryption - **Cloudflare protection**: DDoS protection and security features - **Automatic cleanup**: Tunnels are removed when you stop the process - **No data logging**: We don't store or log your traffic - **Privacy**: Anonymous analytics (can be disabled with `NPORT_ANALYTICS=false`) ## ๐Ÿ†š Comparison with ngrok | Feature | NPort | ngrok | |---------|-------|-------| | Price | 100% Free | Free tier limited | | Custom subdomains | โœ… Always | โŒ Paid only | | HTTPS | โœ… Always | โœ… | | Account required | โŒ No | โœ… Yes | | Time limits | โŒ None (4h auto-cleanup) | โš ๏ธ Free tier limited | | Open source | โœ… MIT | โŒ Proprietary | | Global network | โœ… Cloudflare | โœ… ngrok Edge | | Multilingual | โœ… EN/VI/ES | โŒ English only | ## ๐Ÿงน Cleanup NPort automatically cleans up resources when you: - Press **Ctrl+C** to exit - Kill the process - Terminal closes The cleanup process: 1. โœ… Deletes DNS record (`myapp.nport.link`) 2. โœ… Removes Cloudflare Tunnel 3. โœ… Stops cloudflared process Tunnels also auto-cleanup after **4 hours** to prevent resource waste. ## ๐Ÿ› Troubleshooting ### Binary not found If you see "Cloudflared binary not found": ```bash npm install -g nport --force ``` ### Port already in use Make sure your local server is running on the specified port: ```bash # Check if something is listening on port 3000 lsof -i :3000 # macOS/Linux netstat -ano | findstr :3000 # Windows ``` ### Subdomain already taken Choose a different subdomain name: ```bash nport 3000 -s myapp-v2 ``` ### Connection issues The `ERR Cannot determine default origin certificate path` warning is harmless and can be ignored. It appears because cloudflared checks for certificate-based authentication (we use token-based instead). ### Change language To change your language preference: ```bash nport --language # or nport -l ``` Then select your preferred language from the menu. ## ๐ŸŒ Supported Languages - ๐Ÿ‡บ๐Ÿ‡ธ **English** (`en`) - Default - ๐Ÿ‡ป๐Ÿ‡ณ **Vietnamese** (`vi`) - Tiแบฟng Viแป‡t - ๐Ÿ‡ช๐Ÿ‡ธ **Spanish** (`es`) - Espaรฑol Want to add your language? Contributions are welcome! Check out the [Contributing Guide](docs/CONTRIBUTING.md). ## ๐Ÿค Contributing Contributions are welcome! Please feel free to submit a Pull Request. 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request See [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md) for detailed guidelines. ### Development Setup ```bash # Clone the repository git clone https://github.com/tuanngocptn/nport.git cd nport # Install dependencies npm install # Build TypeScript npm run build # Run tests npm test # Run CLI locally node dist/index.js 3000 -s test ``` ## ๐Ÿ’– Support If you find NPort useful, please consider supporting the project: - โญ [Star on GitHub](https://github.com/tuanngocptn/nport) - โ˜• [Buy me a coffee](https://buymeacoffee.com/tuanngocptn) - ๐Ÿ’ฌ Share with your friends and colleagues - ๐Ÿ› [Report bugs](https://github.com/tuanngocptn/nport/issues) - ๐ŸŒ [Add translations](docs/CONTRIBUTING.md#adding-translations) ## ๐Ÿ“„ License [MIT License](LICENSE) - Feel free to use NPort in your projects! ## ๐Ÿ™ Credits - Created by [Nick Pham](https://github.com/tuanngocptn) from Vietnam - Inspired by [ngrok](https://ngrok.com) and [localtunnel](https://github.com/localtunnel/localtunnel) - Powered by [Cloudflare Tunnels](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/) Cloudflare ## ๐Ÿ”— Links - ๐ŸŒ Website: [https://nport.link](https://nport.link) - ๐Ÿ“ฆ NPM: [https://www.npmjs.com/package/nport](https://www.npmjs.com/package/nport) - ๐Ÿ’ป GitHub: [https://github.com/tuanngocptn/nport](https://github.com/tuanngocptn/nport) - ๐Ÿ“ง Email: tuanngocptn@gmail.com --- Made with โค๏ธ in Vietnam by [Nick Pham](https://github.com/tuanngocptn)