Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/floriansalvi/HEIG-VD_Ocha-api/llms.txt

Use this file to discover all available pages before exploring further.

The Ocha API is configured entirely through a .env file placed at the project root. No configuration is hard-coded: port, database connection, JWT signing secret, and image storage credentials are all read from environment variables at startup. The sections below document each variable, its expected format, and whether it is required or optional.

Environment variables

PORT

PropertyValue
RequiredNo (optional)
Default5001
TypeInteger
The TCP port on which the Express server listens for incoming HTTP connections.
PORT=5001
If you run multiple local services, change this value to avoid port conflicts. The API will be reachable at http://localhost:<PORT>.

MONGO_URI

PropertyValue
RequiredYes
TypeString
The MongoDB connection string used by Mongoose to connect to the database. Supports both local MongoDB instances and hosted clusters such as MongoDB Atlas.
MONGO_URI=mongodb+srv://<username>:<password>@<host>/<database>?<options>
Examples
Local instance
MONGO_URI=mongodb://localhost:27017/ocha
MongoDB Atlas
MONGO_URI=mongodb+srv://admin:[email protected]/ocha?retryWrites=true&w=majority
Keep this value secret. The URI embeds your database credentials. Never commit .env to version control.

JWT_SECRET

PropertyValue
RequiredYes
TypeString
The secret key used to sign and verify JSON Web Tokens. Tokens are valid for 7 days. Any request with a token signed by a different secret will be rejected with a 401 Unauthorized response.
JWT_SECRET=your_long_random_secret_here
Use a cryptographically random string of at least 32 characters. Changing this value in production will immediately invalidate all active sessions, requiring all users to log in again.

CLOUDINARY_URL

PropertyValue
RequiredYes
TypeString
Formatcloudinary://<api_key>:<api_secret>@<cloud_name>
The Cloudinary connection URL used to authenticate image upload requests. Product images are uploaded to Cloudinary via the dedicated image route (PUT /api/v1/products/{productId}/image) and the resulting URL is stored in the Product.image field.
CLOUDINARY_URL=cloudinary://123456789012345:AbCdEfGhIjKlMnOpQrStUvWxYz@my-cloud-name
You can find your api_key, api_secret, and cloud_name in the Cloudinary dashboard under Settings → Access Keys.
The seeded products reference images that must already be published to your Cloudinary account. Upload the product images to Cloudinary before running the seeder if you want them to resolve correctly.

Complete .env example

.env
# Server
PORT=5001

# Database
MONGO_URI=mongodb+srv://<username>:<password>@<host>/<database>?retryWrites=true&w=majority

# Authentication
JWT_SECRET=replace_with_a_long_random_secret

# Image storage
CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>

Useful commands

Seed the database

Populate the database with an initial set of products and stores. Run this once after first setup, or any time you need to restore the baseline data.
npm run seed:all
This command executes both seeders/seedProducts.js and seeders/seedStores.js in sequence. Existing documents with conflicting unique fields will cause the seeder to skip or error on those entries.

Run the test suite

Execute the full Jest integration and unit test suite using Supertest against a dedicated test database.
npm run test
Configure a separate MONGO_URI for your test environment if you do not want tests to write to your development or production database. The test setup in tests/setup/testDB.js manages the test database lifecycle.

Start the server

# Development mode (with hot reload)
npm run dev

# Production mode
npm run start
The API will be available at http://localhost:<PORT>/api/v1 and the Swagger UI at http://localhost:<PORT>/api/v1/api-docs.

Build docs developers (and LLMs) love