Backend — Environment & Configuration

Installing dependencies, .env setup, and database initialization

Step 1 — Install Backend Dependencies

In the VS Code terminal with pos-backend open, run:

bash

This downloads all required packages. It takes 1–3 minutes. Wait for the cursor to return.

Step 2 — Create the .env File

In the VS Code file sidebar, right-click in an empty area › New File. Name it exactly: .env (note the leading dot — it is intentional).

Copy every variable from the table below and fill in your values.

Full .env Variable Reference

VariableDescriptionExample / Format
NODE_ENVRuntime environment modedevelopmentRequired
PORTBackend HTTP server port5000Required
DATABASE_URLPostgreSQL connection stringpostgresql://user:pass@host/dbRequired
DIRECT_URLDirect DB URL (Prisma migrations)postgresql://user:pass@host/dbRequired
REDIS_URLRedis connection stringredis://localhost:6379Required
JWT_ACCESS_SECRETAccess token signing secret64-char hex stringRequired
JWT_REFRESH_SECRETRefresh token signing secret64-char hex string (different)Required
JWT_ACCESS_EXPIRES_INAccess token expiry15mRequired
JWT_REFRESH_EXPIRES_INRefresh token expiry7dRequired
CLOUDINARY_CLOUD_NAMECloudinary cloud identifiermy-cloud-nameRequired
CLOUDINARY_API_KEYCloudinary API key123456789012345Required
CLOUDINARY_API_SECRETCloudinary API secretabc123xyz...Required
FRONTEND_URLFrontend origin — used for CORShttp://localhost:3000Required
LOG_LEVELPino log verbosityinfoOptional
RATE_LIMIT_WINDOW_MSRate limit window in milliseconds900000Optional
RATE_LIMIT_MAXMax requests per window100Optional

Generating Secure JWT Secrets

Run this command twice in any terminal. Use the first output for JWT_ACCESS_SECRET and the second for JWT_REFRESH_SECRET. They must be different values.

bash

Getting Your PostgreSQL Database URL

  1. Go to neon.tech and create a free account. Click Create Project.
  2. After creation, click Connection Details and copy the Connection String.
  3. It looks like: postgresql://user:pass@host.neon.tech/dbname?sslmode=require
  4. Use this exact string for both DATABASE_URL and DIRECT_URL.

Local PostgreSQL

Download from postgresql.org/download and install with defaults. Create a database named posdb:

sql

Your local URL will be:

Getting Your Redis URL

Go to upstash.com, create a free account, and create a Redis database. Copy the Redis URL from the dashboard — it starts with rediss://.

Local Redis

  • Windows: Install Memurai from memurai.com
  • macOS: brew install redis then brew services start redis
  • Linux: sudo apt install redis-server then sudo systemctl start redis
  • Local URL: redis://localhost:6379

Getting Cloudinary Credentials

  1. Go to cloudinary.com and create a free account.
  2. From your Dashboard, copy the Cloud Name, API Key, and API Secret.
  3. Paste each into the corresponding .env variable.

Step 3 — Database Initialization

Run these four commands in order in your backend terminal. Do not skip any.

CommandWhat It Does
npm run db:generateGenerates the Prisma client — the type-safe database access layer
npm run db:migrateCreates all tables in the database. When prompted, enter: initial_setup
npm run db:seedPopulates demo data: products, categories, customers, a sample tenant
npm run db:seed:super-adminCreates the platform Super Admin account. Save the credentials shown
Note

Run db:migrate only once on a fresh database. For future code updates use npm run db:migrate:prod — it applies only new changes without prompts or data loss.