Quickstart Guide
Get the Tanqueo Backend API up and running in just a few minutes.Prerequisites
Before you begin, ensure you have:- Node.js 18.x or higher installed
- PostgreSQL database (or Supabase account)
- npm or yarn package manager
- Git (optional, for cloning)
Installation
Install Dependencies
Install all required npm packages:This will install:
- Express.js for the web server
- Supabase client for database and auth
- TypeScript and development tools
- CORS and middleware packages
Configure Environment Variables
Create a
.env file in the root directory with your configuration:.env
You can find your Supabase credentials in your Supabase project settings under API.
Build the TypeScript Code
Compile the TypeScript source to JavaScript:This creates the
dist/ directory with compiled JavaScript files.Verify Installation
Test that the server is running correctly:Your First API Request
1. Authenticate
First, obtain an access token by logging in:Save the
access_token - you’ll need it for subsequent requests.2. Make an Authenticated Request
Use the access token to fetch fuel records (tanqueos):3. Refresh Your Token
When your access token expires (default: 1 hour), refresh it:Common Configuration Options
CORS Configuration
The server is configured to accept requests from the frontend URL specified in.env:
Port Configuration
Change the server port by setting thePORT environment variable:
Next Steps
Authentication Guide
Learn about JWT tokens, refresh mechanisms, and security
Architecture Overview
Understand the system architecture and design patterns
Data Models
Explore the TypeScript interfaces and data structures
Error Handling
Learn how to handle errors and status codes
Troubleshooting
Server Won’t Start
Missing environment variables
Missing environment variables
Error:
SUPABASE_URL y SUPABASE_ANON_KEY deben estar definidos en .envSolution: Ensure your .env file contains both SUPABASE_URL and SUPABASE_ANON_KEY.Port already in use
Port already in use
Error:
EADDRINUSE: address already in useSolution: Either stop the process using port 5000, or change the PORT in your .env file.TypeScript compilation errors
TypeScript compilation errors
Error: Build fails with TypeScript errorsSolution: Ensure you’re using TypeScript 5.9.3 or higher:
npm install typescript@latestAuthentication Issues
- 401 Unauthorized: Check that your token is valid and not expired
- Invalid credentials: Verify your email and password are correct in Supabase Auth
- User not found: Ensure the user exists in both Supabase Auth and the
usuariostable