This is a simple TCP chat application built with Node.js that demonstrates how to use TCP sockets and deploy to Clever Cloud.
This application is a TCP-based chat room where users can connect via a TCP client (like nc or telnet), send messages, and change their alias. It uses:
- TCP sockets for real-time chat communication
- HTTP server to display connection instructions
- ANSI escape codes for terminal UI rendering
- Real-time multi-user chat over TCP
- Colorized terminal UI with message history
- Custom aliases with
/alias <name> - Automatic message splitting for long messages
- Node.js 24+ - JavaScript runtime
- chalk - Terminal string styling
- ansi-escapes - ANSI escape codes for terminal manipulation
- Node.js 24+
- npm
npm install
npm startThe HTTP server will be accessible at http://localhost:8080 and the TCP chat at port 4040.
Connect to the chat with:
nc localhost 4040For development with auto-restart on file changes:
npm run start:devYou have two options to deploy your application on Clever Cloud: using the Web Console or using the Clever Tools CLI.
If you don't already have an account, go to the Clever Cloud console and follow the registration instructions.
- Log in to the Clever Cloud console
- Click on "Create" and select "An application"
- Choose "Node.js" as the runtime environment
- Configure your application settings (name, region, etc.)
- In your application's dashboard, go to "TCP Redirections"
- Add a new TCP redirection
- Set the
TCP_PORTenvironment variable (e.g.,4040) - Set the
PUBLIC_TCP_PORTenvironment variable to the public port assigned by Clever Cloud
You can deploy your application using Git:
# Add Clever Cloud as a remote repository
git remote add clever git+ssh://git@push-par-clevercloud-customers.services.clever-cloud.com/app_<your-app-id>.git
# Push your code to deploy
git push clever masterInstall the Clever Tools CLI following the official documentation:
# Using npm
npm install -g clever-tools
# Or using Homebrew (macOS)
brew install clever-toolsclever login# Initialize the current directory as a Clever Cloud application
clever create --type node <YOUR_APP_NAME>
# Set TCP port
clever env set TCP_PORT 4040
# Add a TCP redirection and set the public port
PUBLIC_TCP_PORT=$(clever tcp-redirs add --namespace cleverapps | sed 's/.*: //g')
clever env set PUBLIC_TCP_PORT ${PUBLIC_TCP_PORT}clever deployOnce deployed, you can access your application at the URL provided by Clever Cloud.
clever openIt will display a nc command to connect to your TCP chat.
Once deployed, you can monitor your application through:
- Web Console: The Clever Cloud console provides logs, metrics, and other tools to help you manage your application.
- CLI: Use
clever logsto view application logs andclever statusto check the status of your application.
