The Amigo Invisible backend is a Node.js application built with Express 5, using Mongoose as the MongoDB ODM, Nodemailer for automated email delivery, and dotenv for environment configuration. In production it is deployed as a serverless function on Vercel via theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Sufianeh7/AmigoInvisible/llms.txt
Use this file to discover all available pages before exploring further.
@vercel/node builder, while locally it runs as a conventional HTTP server with nodemon for live-reloading.
Directory Structure
Entry Point
index.js is the application entry point. It performs the following tasks in order:
- Loads environment variables from
.envviadotenv. - Creates the Express app instance.
- Applies the
cors()andexpress.json()middleware so the Angular frontend can communicate with it across origins and send JSON payloads. - Opens a connection to MongoDB using
mongoose.connect()with theMONGO_URIenvironment variable. - Imports and mounts the draw routes under the
/api/sorteosprefix. - Conditionally starts the HTTP listener only when
NODE_ENV !== 'production', then exportsappso Vercel can consume it as a serverless handler.
The HTTP listener is wrapped in
if (process.env.NODE_ENV !== 'production'). This means the server starts normally during local development, but when deployed to Vercel, the app module is simply exported and Vercel manages the request lifecycle — no listener is started, avoiding port conflicts in the serverless environment.Key Dependencies
express ^5.2.1
HTTP server and routing framework. Version 5 brings native async/await error propagation, so unhandled promise rejections inside route handlers are automatically forwarded to Express error middleware.
mongoose ^9.7.0
MongoDB ODM used to define the
Sorteo schema, validate documents, and interact with the database through a clean model API.nodemailer ^8.0.10
Handles all outbound email delivery. Configured with a Gmail SMTP transporter to send personalized Secret Santa reveal emails to each participant.
uuid ^14.0.0
Listed as a dependency, though the controller uses Node’s built-in
crypto.randomUUID() directly to generate the unique adminToken for each group.dotenv ^17.4.2
Loads environment variables from a
.env file at startup. Required variables include MONGO_URI, EMAIL_USER, and EMAIL_PASS.cors ^2.8.6
Enables cross-origin resource sharing so the Angular frontend (served on a different origin during development) can make API requests without being blocked by the browser.
Local Development
Install dependencies and start the development server withnodemon for automatic restarts on file changes:
http://localhost:3000 by default. Make sure you have a .env file in the Node/ directory with the following variables set before starting: