This guide walks you through cloning the Factus Challenge repository, wiring up your environment variables, and verifying that the backend can communicate with the Factus API — all the way to opening the frontend in your browser and issuing your first invoice.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/factus_challenge/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, make sure you have the following ready:- Node.js 22+ — the backend uses
--env-file(native.envloading) and ES modules, both of which require Node.js 22 - PostgreSQL — a local instance or a managed service (the project was tested on Azure Database for PostgreSQL)
- A Factus API account — sign up at factus.com.co and obtain your
client_id,client_secret,email, andpasswordfor the sandbox (api-sandbox.factus.com.co) or production environment
Steps
Clone the repository
Clone the project from GitHub and move into the root directory:The repository contains two top-level directories:
bc-v1/— the Node.js/Express backendfr-v1/— the static HTML/JS frontend
Install backend dependencies
Navigate into the backend directory and install all npm packages:This installs the five runtime dependencies declared in
package.json:| Package | Purpose |
|---|---|
axios | HTTP client for proxying requests to the Factus API |
express | Web framework and HTTP router |
morgan | Request logger (prints to stdout in dev format) |
pg | PostgreSQL connection pool client |
qs | URL-encodes the OAuth 2.0 token request body |
Create the .env file
Create a Variable reference:
.env file inside bc-v1/. The server loads it automatically via Node’s --env-file flag when you run npm run dev.| Variable | Required | Description |
|---|---|---|
PORT | No | Port the Express server listens on. Defaults to 4500. |
url_api | Yes | Base URL of the Factus API (sandbox or production). |
client_id | Yes | OAuth 2.0 client ID from your Factus application. |
client_secret | Yes | OAuth 2.0 client secret from your Factus application. |
email | Yes | Your Factus account email (used as the OAuth username). |
password | Yes | Your Factus account password (used for the password grant type). |
refresh_token | No | If provided, the token manager uses refresh_token grant instead of password grant on startup. |
DB_USER | Yes | PostgreSQL username. |
DB_HOST | Yes | PostgreSQL host. |
DB_NAME | Yes | PostgreSQL database name. |
DB_PASSWORD | Yes | PostgreSQL password. |
DB_SSL | Yes | Set to true to require SSL for the database connection. |
Start the backend server
From inside This executes
bc-v1/, run:node --env-file .env --watch ./src/main.js. On startup, the server:- Fetches an OAuth 2.0 token immediately by calling
POST /oauth/tokenon the Factus API, storing the resultingaccess_tokenandrefresh_tokeninprocess.env - Starts Express on port
4500(or the value ofPORT) - Schedules a token refresh every 55 minutes (3,300,000 ms) via
setInterval
The server auto-refreshes the OAuth access token every 55 minutes in the background. You do not need to restart the process to keep the token valid — this is handled entirely by
bc-v1/src/auth/token.js.Configure the frontend
The frontend reads its backend URL from a single JSON file. Open If your backend is deployed remotely (e.g., on Koyeb), replace
fr-v1/resources/assets/config.json and verify (or update) the url field to point at your running backend:http://localhost:4500 with your deployment URL:Open the frontend in a browser
The frontend is fully static — no build step required. Simply open the entry point in your browser:The page loads Bootstrap 5.3.3 (Vapor dark theme) and Tabulator 6.3 from self-hosted files in
fr-v1/resources/utils/ and immediately starts making requests to the backend URL defined in config.json.Verify the Backend Is Working
Once the server is running, confirm it can reach the Factus API by listing invoices. Send aGET request to the /factura endpoint:
data array contains invoices returned by the Factus API):
500 or a token-related error, double-check that url_api, client_id, client_secret, email, and password are all set correctly in your .env file.
