This guide walks you through cloning the repository, wiring up the required environment variables, starting the development server, registering a lawyer account, and making an authenticated request to list all reservations — everything you need to verify that the API is working end-to-end on your machine.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/despacho-backend/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, make sure the following are available in your environment:
- Node.js 18 or later — the project uses native ES modules and
performance.now()at startup. Runnode -vto confirm. - npm — bundled with Node.js. Run
npm -vto confirm. - A MongoDB instance — either a locally running
mongodprocess or a free MongoDB Atlas cluster. You will need the connection URI in the next step.
Clone and install dependencies
Clone the repository and install all npm dependencies:npm will install Express, Mongoose, jsonwebtoken, bcrypt, Socket.io, multer, dotenv, morgan, and the nodemon dev dependency.
Configure environment variables
Despacho Backend reads all configuration from a Then populate it with the three required variables:
.env file in the project root via dotenv. Create the file now:| Variable | Description |
|---|---|
PORT | The port the Express HTTP server will listen on. Defaults to 3000 if omitted. |
SECRET | The signing secret for JWTs. Must be a long, random string — see Configuration for generation tips. |
MONGODB_URL | Full MongoDB connection URI. Use mongodb://localhost:27017/despacho for a local instance or your Atlas connection string. |
Start the development server
Run the dev script, which uses nodemon to restart on file changes:If your environment is configured correctly you will see:If you see
Error connecting to Mongoose ❌ instead, double-check that your MONGODB_URL is reachable and that mongod is running (or your Atlas cluster is active).Create a lawyer account
With the server running, register the first lawyer account by posting to A successful response looks like:If the email is already registered the API returns HTTP 203 with
POST /api/lawyer/user/create. The endpoint accepts email and password in the JSON body, hashes the password with bcrypt, and saves the document with the Admin role."status": false.Log in and retrieve your JWT
Call The response includes the JWT in the
POST /api/lawyer/user/login with the same credentials to receive a signed JWT valid for 365 days.token field:Copy the value of
token and keep it handy — you will pass it as a Bearer token in the Authorization header of every subsequent request to a protected endpoint. The token is also stored on the LawyerUser document in MongoDB for reference.Call a protected endpoint
Every reservation listing and management route is protected by the A successful response returns a paginated list of all reservations (empty array if none have been submitted yet) along with pagination metadata:If you omit the
Token middleware, which expects an Authorization: Bearer <token> header. Use the token from the previous step to list all reservations:Authorization header, the Token middleware returns HTTP 401 {"msj": "Sin autorizacion", "status": false}. If the token is expired or invalid, it returns HTTP 403.