Skip to main content

Environment Configuration

The André Ruperto Portfolio requires environment variables for the backend to function properly. These variables control database connections, email services, authentication, and server configuration.

Backend Environment Variables

Create a .env file in the backend/ directory with the following variables:
backend/.env
cp backend/.env.example backend/.env

Required Variables

1

Database URL

Configure your PostgreSQL database connection:
DATABASE_URL=postgresql://USER:PASSWORD@HOST:PORT/DATABASE
Example:
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/portfolio
Replace USER, PASSWORD, HOST, PORT, and DATABASE with your actual PostgreSQL credentials.
2

Resend API Key

Set up email functionality with Resend:
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxx
How to get your API key:
  1. Sign up at resend.com
  2. Navigate to API Keys section
  3. Create a new API key
  4. Copy and paste it into your .env file
The Resend API is used for the contact form functionality.
3

Admin Password

Set a secure password for accessing admin features:
ADMIN_PASSWORD=sua_senha_segura
Use a strong, unique password. This password is used to access email previews and admin features.
4

JWT Secret

Generate a secure JWT secret for authentication:
JWT_SECRET=gere-um-secret-com-o-comando-abaixo
Generate a secure secret:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
Copy the output and use it as your JWT_SECRET.
5

Server Port

Configure the backend server port (optional):
PORT=3001
Default is 3001. Change if this port is already in use.
6

Node Environment

Set the Node environment:
NODE_ENV=development
Use development for local development and production for deployment.

Complete .env Example

# Database URL (PostgreSQL)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/portfolio

# Resend API Key
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxx

# Admin Password
ADMIN_PASSWORD=your_secure_password_here

# JWT Secret
JWT_SECRET=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6

# Server Port
PORT=3001

# Environment
NODE_ENV=development

Frontend Configuration

The frontend uses Vite and requires no separate environment file. Configuration is handled in vite.config.ts:
vite.config.ts
server: {
  host: "::",
  port: 8080,
  proxy: {
    "/api": {
      target: "http://localhost:3001",
      changeOrigin: true,
    },
  },
}
The frontend runs on port 8080 and proxies API requests to the backend on port 3001.

Database Schema

The project uses Prisma ORM with PostgreSQL. The main model is:
schema.prisma
model Project {
  id          Int      @id @default(autoincrement())
  title       String
  description String
  tags        String[]
  image       String?
  links       Json
  github      String?
  order       Int      @default(0)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

Verification

Verify your environment setup:
# Check if environment variables are loaded
cd backend
node -e "require('dotenv').config(); console.log(process.env.DATABASE_URL)"

# Test database connection with Prisma
npm run backend:generate

Security Best Practices

  • Never commit .env files to version control
  • Use strong, unique passwords and secrets
  • Rotate JWT secrets regularly in production
  • Use different credentials for development and production
  • Keep your Resend API key private

Next Steps

Build docs developers (and LLMs) love