This is a simple Node.js application that demonstrates how to use Apache Pulsar for message processing with sentiment analysis, and deploy it to Clever Cloud.
This application displays a form where you can send a message. It assesses the mood of your message and tells if it's positive or negative. It uses:
- Apache Pulsar for message queuing between the server and worker
- Socket.IO for real-time communication with the client
- VADER for sentiment analysis (local, no external API needed)
- The client sends a message to the Express server
- The server publishes the message onto an Apache Pulsar topic
- A worker consumes the message, runs sentiment analysis, and publishes the result to another topic
- The server reads the result and pushes it to the client via WebSocket
GET /- Renders the main page with the message formPOST /messages- Submit a message for sentiment analysis
- Express.js 5 - Web framework for Node.js
- Socket.IO 4 - Real-time bidirectional communication
- pulsar-client - Apache Pulsar client for Node.js
- Tailwind CSS 4 - Utility-first CSS framework
- vader-sentiment - VADER sentiment analysis
- esbuild - JavaScript bundler
- Node.js 24+
- Node.js 24+
- npm
npm install
npm run buildSet the required environment variables (duplicate .env.example and fill the ADDON_PULSAR_ variables):
cp .env.example .envYou can either deploy a standalone Pulsar locally with Docker or use the Clever Cloud Pulsar add-on.
Start the server and worker:
npm start
# In another terminal
npm run workerThe application will be accessible at http://localhost:3000.
You 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 "Service dependencies"
- Click "Link add-ons" and select "Pulsar"
- Choose the plan that fits your needs
- Link the add-on to your application
The ADDON_PULSAR_* environment variables will be automatically set.
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>
# Add a Pulsar add-on
clever addon create addon-pulsar <YOUR_ADDON_NAME> --link <YOUR_APP_NAME>cat .env.prod.example | clever env importclever deployOnce deployed, you can access your application at the URL provided by Clever Cloud.
clever openOnce 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.