Skip to content

CleverCloud/nodejs-tcp-chat-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js TCP Chat Example Application on Clever Cloud

Clever Cloud - PaaS

This is a simple TCP chat application built with Node.js that demonstrates how to use TCP sockets and deploy to Clever Cloud.

screenshot of the TCP chat

About the Application

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

Features

  • Real-time multi-user chat over TCP
  • Colorized terminal UI with message history
  • Custom aliases with /alias <name>
  • Automatic message splitting for long messages

Technology Stack

Prerequisites

  • Node.js 24+
  • npm

Running the Application Locally

npm install
npm start

The HTTP server will be accessible at http://localhost:8080 and the TCP chat at port 4040.

Connect to the chat with:

nc localhost 4040

For development with auto-restart on file changes:

npm run start:dev

Deploying on Clever Cloud

You have two options to deploy your application on Clever Cloud: using the Web Console or using the Clever Tools CLI.

Option 1: Deploy using the Web Console

1. Create an account on Clever Cloud

If you don't already have an account, go to the Clever Cloud console and follow the registration instructions.

2. Set up your application on Clever Cloud

  1. Log in to the Clever Cloud console
  2. Click on "Create" and select "An application"
  3. Choose "Node.js" as the runtime environment
  4. Configure your application settings (name, region, etc.)

3. Configure TCP Redirection

  1. In your application's dashboard, go to "TCP Redirections"
  2. Add a new TCP redirection
  3. Set the TCP_PORT environment variable (e.g., 4040)
  4. Set the PUBLIC_TCP_PORT environment variable to the public port assigned by Clever Cloud

4. Deploy Your Application

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 master

Option 2: Deploy using Clever Tools CLI

1. Install Clever Tools

Install the Clever Tools CLI following the official documentation:

# Using npm
npm install -g clever-tools

# Or using Homebrew (macOS)
brew install clever-tools

2. Log in to your Clever Cloud account

clever login

3. Create a new application

# 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}

4. Deploy your application

clever deploy

5. Open your application in a browser

Once deployed, you can access your application at the URL provided by Clever Cloud.

clever open

It will display a nc command to connect to your TCP chat.

Monitoring Your Application

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 logs to view application logs and clever status to check the status of your application.

Additional Resources

About

Run a dead simple TCP chat on Clever Cloud

Topics

Resources

Stars

Watchers

Forks

Contributors