This is a simple Express.js application that demonstrates how to build a CRUD web app backed by MongoDB with StatsD metrics, and deploy it to Clever Cloud.
In October 2018, MongoDB Inc. switched the server license from the open-source GNU AGPL v3 to the Server Side Public License (SSPL), starting with version 4.2. The SSPL is not recognized as open source by the OSI and imposes restrictions that are incompatible with how cloud providers operate. As a result, major Linux distributions (Debian, Fedora, RHEL...) dropped MongoDB from their repositories, and most cloud providers stopped offering newer versions.
Clever Cloud chose to stay with MongoDB 4.0.3, the last version released under the truly open-source AGPL v3 license. This means the Mongoose ODM version used in your application must remain compatible with MongoDB 4.0. In practice, this limits us to Mongoose 6.x, since Mongoose 7+ requires MongoDB 4.4 at minimum.
This is why the package.json pins "mongoose": "^6.13.9". Despite the official compatibility table claiming Mongoose 7 and 8 support MongoDB 4.0.x, they bundle MongoDB Node.js driver 5+ and 6+ respectively, which require wire protocol version 8 (MongoDB 4.2+). Only Mongoose 6 (driver 4.x) works with MongoDB 4.0.3's wire protocol version 7.
This application is a simple value list where you can add or delete entries. It uses:
- MongoDB for data persistence
- StatsD for tracking metrics (creations, deletions, and a gauge for total values)
GET /- Renders the main page with all valuesPOST /values- Create a new valueDELETE /values/:id- Delete a value by ID
- Express.js 4 - Web framework for Node.js
- Mongoose 6 - MongoDB object modeling
- Pug 3 - Template engine
- Bootstrap 5 - Frontend CSS framework
- hot-shots - StatsD client
- Node.js 22+
- MongoDB 4.0.3
- Node.js 22+
- npm
npm install
npm startThe application will be accessible at http://localhost:8080.
The application requires a running MongoDB instance. Set the
MONGODB_ADDON_URIenvironment variable to your MongoDB connection string.
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 "MongoDB"
- Choose the plan that fits your needs
- Link the add-on to your application
The MONGODB_ADDON_URI environment variable 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 MongoDB add-on
clever addon create mongodb-addon <YOUR_ADDON_NAME> --link <YOUR_APP_NAME>clever 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.