The Estructuras Backend API is configured entirely through environment variables loaded from aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nelrondon/backend-proyecto-estructuras/llms.txt
Use this file to discover all available pages before exploring further.
.env file at the project root via dotenv. There is no separate configuration UI or runtime config endpoint — every setting is resolved at startup from src/config.js and src/db.js. This page documents every variable, the CORS allowlist, the Turso database connection, and the security defaults baked into the server.
Environment Variables
Place these variables in a.env file at the root of the repository (alongside package.json). The server reads them once at startup; a restart is required for changes to take effect.
The TCP port the Express HTTP server will bind to. Override this when deploying to a host that assigns a dynamic port via the environment (e.g.,
process.env.PORT on Render or Railway).The secret string used by
jsonwebtoken to sign and verify all JWT session tokens. Both createAccessToken and verifyToken in src/libs/jwt.js read this value from src/config.js. If this variable is absent the server will start but JWT signing will fail, breaking all authentication endpoints.The Turso authentication token passed to See Database Setup below for instructions on obtaining this token.
@libsql/client as authToken. The database URL is hardcoded in src/db.js as libsql://estructuradb-nelrondon.aws-us-east-1.turso.io. If this token is missing or invalid, every database query will throw an authentication error.The bcrypt cost factor used when hashing user passwords. Higher values increase security but also increase the CPU time spent on each registration or login. A value of
10 is the bcrypt default and is appropriate for most deployments; increase to 12 or 14 on hardware that can absorb the extra cost.This value is read by the UserModel at runtime. Changing it only affects new passwords — existing password hashes in the database are unaffected because bcrypt stores the cost factor inside the hash string itself.
Database Setup
Estructuras uses Turso — a globally distributed SQLite-compatible database built on libSQL — as its persistence layer. The connection is established insrc/db.js:
url value in src/db.js to your own Turso database URL and supply the corresponding token in DB_TOKEN.
Obtaining a Turso Auth Token
- Install the Turso CLI:
curl -sSfL https://get.tur.so/install.sh | bash - Log in:
turso auth login - Create a token for your database:
- Copy the printed JWT string and set it as
DB_TOKENin your.env.
CORS Allowed Origins
The server enforces a static origin allowlist defined insrc/config.js. Requests from any origin not on this list are rejected with a CORS error before reaching any route handler.
src/index.js also passes through requests with no Origin header (e.g., server-to-server calls, curl without an Origin flag, and Postman by default):
Adding a New Allowed Origin
To permit an additional frontend (for example, a staging deployment athttps://staging.myapp.com), open src/config.js and append the origin to the array:
--watch flag used in pnpm start will detect the change and restart automatically.
Security Settings
The following security behaviors are hardcoded insrc/index.js and src/controllers/auth.controller.js. They are not configurable through environment variables but are documented here for reference.
Disabled X-Powered-By Header
X-Powered-By: Express response header that reveals the server framework to anyone who inspects the response. This is disabled globally to reduce information leakage.
JWT Cookie Attributes
Every session token is issued with the following cookie attributes:| Attribute | Value | Effect |
|---|---|---|
httpOnly | true | The cookie cannot be read by document.cookie or any JavaScript — it is managed entirely by the browser |
secure | true | The cookie is only sent over HTTPS; it will not be sent over plain HTTP |
sameSite | "none" | Allows the cookie to be sent on cross-site requests, which is necessary when the frontend is on a different domain (e.g., Vercel) than the API |
maxAge | 604800000 ms | The cookie and the JWT inside it both expire after exactly 7 days |
Because
secure: true is set unconditionally, the authentication cookie will not be sent by browsers over http:// — including http://localhost. When developing locally with a browser-based frontend, either serve the frontend and API over HTTPS (e.g., using mkcert) or temporarily adjust the cookie options in src/controllers/auth.controller.js for local development only.JWT Expiry
Tokens are signed withexpiresIn: "7d" in src/libs/jwt.js. After 7 days the token’s exp claim will be in the past and jwt.verify will throw a TokenExpiredError, causing protected endpoints to return 401 Unauthorized. The user must log in again to receive a new token.