Skip to the article

CloselineEnvironment variables

Environment variables

What each setting in the Closeline API's and the frontends' .env files does, which ones you need, and the Docker Compose options.

For the Full Stack package

Where the settings live

FileRead byHolds secrets
back-end/.envThe API, with yarn dev and inside Docker ComposeYes. Never commit it.
dashboard/.envThe CRM dashboard, at build time (and PORT when it starts)No. Every value is public.
website/.envThe website, at build timeNo. Every value is public.
.env beside docker-compose.ymlDocker Compose, for the full stack: ports, addresses, the first startOnly the first account's password

Create each app's file from the .env.example beside it, which documents every variable: cp .env.example .env. The examples work as they are for a local run.

Where the settings live

One file, .env in the website's folder, read when the website is built. Every value in it is optional and public, so it never holds a secret. Create it from .env.example, which points at an API on http://localhost:8000/api and a dashboard on http://localhost:3031: cp .env.example .env. With no .env, or NEXT_PUBLIC_API_BASE_URL empty, the website runs on its built-in sample data.

Where the settings live

One file, .env in the dashboard's folder, read when the dashboard is built, and for PORT when it starts. Every value in it is public, so it never holds a secret: payment and AI keys live in the API's settings. Create it from .env.example, which points at an API on http://localhost:8000/api: cp .env.example .env. With no .env, or NEXT_PUBLIC_API_BASE_URL empty, the dashboard runs on its built-in sample data.

Where the settings live

One file, .env in the API's folder, read by the API with yarn dev and yarn start:prod. It holds secrets: never commit it. Create it from .env.example, which documents every variable and works as it is for a local run: cp .env.example .env.

The Docker image sets its own defaults, so docker run works without a file: NODE_ENV=production, SQLite at /data/database.sqlite, uploads in /data/uploads, CORS_ORIGIN for the two local frontends, the local addresses and SEED_SAMPLE_DATA=true. Override any of them with -e, one value each, rather than --env-file with a copy of .env.example.

API essentials

The API checks JWT_SECRET and, in production, CORS_ORIGIN before it starts. If one is missing or unusable, it stops with one line saying what to fix.

VariableWhat it does
NODE_ENVdevelopment locally, which creates and updates the tables on start. production on a server, which never touches the tables.
PORTThe API's port, 8000. Both frontends point at it.
DB_TYPEsqlite (as in .env.example) or mysql.
SQLITE_DATABASEPath of the SQLite file, ./database.sqlite, relative to the API's folder.
JWT_SECRETSigns every sign-in. Required. The example value is accepted outside production only.
JWT_EXPIRATIONHow long a sign-in lasts, 7d.
CORS_ORIGINThe website's and the dashboard's addresses, comma separated. Unset, only http://localhost:3030 and http://localhost:3031 are allowed; required in production.
FRONTEND_URLThe dashboard's address, the only origin its live permission updates are accepted from.
DASHBOARD_URLThe dashboard's address, written into invitation and password-reset links, billing notices and the pages a checkout returns to.
PUBLIC_API_URLThis API as the browser reaches it, for the signed invoice download links.
PUBLIC_MEDIA_URLThe address /media is reached at from a browser, http://localhost:8000/media.
MEDIA_UPLOAD_DIRWhere uploads are written when no bucket is set, ./public/media/uploads.
RATE_LIMIT_LOGINFailed sign-ins one address may make in 15 minutes before 429, 10.
TRUST_PROXYThe number of reverse proxies in front of the API (1 behind Nginx, Caddy or a load balancer, 2 with Cloudflare in front of that), so the sign-in limit counts the real visitor. Empty when the API is reached directly.

Generate your own JWT_SECRET with:

Terminal
node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"

A start without the sample accounts

VariableWhat it does
SEED_SAMPLE_DATADocker only, on a new volume: true (the default) seeds the sample workspace and its published sign-ins, false starts it empty.
ADMIN_EMAIL, ADMIN_PASSWORDYour first account, created by yarn admin:create (or on the first Docker start with SEED_SAMPLE_DATA=false), with a workspace of its own and the installation's Platform admin role. The password needs 8 to 128 characters.
ADMIN_NAMEOptional: that account's name, Workspace Admin when empty.
ADMIN_WORKSPACEOptional: its workspace's name, named after the first name when empty.

With the full stack's Docker Compose, set these in the .env beside docker-compose.yml: compose passes them from there, not from back-end/.env.

Use MySQL instead of SQLite

Create an empty database, then set the driver and the connection in the API's .env:

The API's .env
DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=your-password
DB_DATABASE=closeline

Then run yarn seed for the sample workspace, or yarn admin:create for your own first account with no sample data; both create the tables. The running API only creates and updates the tables itself when NODE_ENV=development, so with NODE_ENV=production one of those commands runs before the first start (yarn seed:prod or yarn admin:create:prod after yarn build), and yarn schema:prod after an update. The Docker image creates the database by itself on SQLite only.

Website and dashboard

Every NEXT_PUBLIC_* value is compiled into the JavaScript the browser loads, and anyone who opens the page can read it. Never put a secret in these files, and restart yarn dev or build again after changing one. With Docker, pass them as --build-arg.

VariableAppWhat it does
NEXT_PUBLIC_API_BASE_URLBothThe API's address including /api, http://localhost:8000/api in .env.example and the Docker builds. Empty, the app runs on its built-in sample data with no API.
NEXT_PUBLIC_WEBSOCKET_BASE_URLDashboardThe API's address without /api, for live permission updates. Empty uses NEXT_PUBLIC_API_BASE_URL without its /api.
NEXT_PUBLIC_BASE_URLDashboardThe dashboard's own public address, http://localhost:3031: robots.txt, the sitemap and the page metadata.
NEXT_PUBLIC_WEBSITE_URLDashboardThe website, http://localhost:3030: the sidebar's Help link, the sign-up page's Privacy and Terms links and the way back to the website from the sign-in pages.
PORTDashboardThe port yarn dev and yarn start use, 3031.
NEXT_PUBLIC_SITE_URLWebsiteThe website's public address, http://localhost:3030: canonical links, language alternates, the sitemap and the sharing cards.
NEXT_PUBLIC_DASHBOARD_URLWebsiteThe dashboard, http://localhost:3031: Sign in, Start free, the plans' Choose buttons and the /start, /auth/ and /demo addresses hand over to it.
API_INTERNAL_URLWebsiteOptional, server only, read when it starts. Where the website's own server reaches the API when the browser's address does not work from inside it, as in Docker Compose (http://api:8000/api). Empty uses NEXT_PUBLIC_API_BASE_URL.
NEXT_PUBLIC_SAMPLE_DATA_NOTICEWebsiteOptional. always also shows the "Sample data" notice in a production build while a configured API is not answering.
BUILD_STANDALONEBothBuild only: true makes yarn build write a self-contained server into .next/standalone, which the Dockerfiles set. Leave it unset for yarn start.

The website's port is 3030 in its package.json: for another, run yarn next dev -p <port>, or yarn next start -p <port> after yarn build. AI provider keys and payment keys never go in a frontend: they live in the API's .env only.

Ports

With the full stack in Docker, three variables in the .env beside docker-compose.yml set the ports on your computer. Change one when another program already uses it, such as ADMIN_PORT=3041, and run docker compose up --build again.

VariableDefaultApp
SITE_PORT3030The website
ADMIN_PORT3031The CRM dashboard
API_PORT8000The API

Every address built from them follows by itself: the API's CORS_ORIGIN, FRONTEND_URL, DASHBOARD_URL, PUBLIC_API_URL and PUBLIC_MEDIA_URL, and the frontends' API and dashboard addresses. Inside its container each app keeps its own port, so the API's start-up line still says http://localhost:8000/api; the browser address follows API_PORT.

  • One app with `docker run`: change the number on the left of -p, such as -p 3041:3031. A frontend on a new address is built again with its own address (NEXT_PUBLIC_BASE_URL for the dashboard, NEXT_PUBLIC_SITE_URL for the website) and added to the API's CORS_ORIGIN; the dashboard's is also the API's FRONTEND_URL and DASHBOARD_URL. The API on a new port gets PUBLIC_API_URL and PUBLIC_MEDIA_URL to match, and both frontends are built with NEXT_PUBLIC_API_BASE_URL pointing at it.
  • Without Docker: PORT in the API's .env and in the dashboard's .env, and -p for the website, with the same addresses changed to match.

Docker Compose options

Nothing has to be set for a local run. To change something, put it in a .env file beside docker-compose.yml and run docker compose up --build again: the frontends compile these values in.

VariableDefaultWhat it does
SITE_PORT, ADMIN_PORT, API_PORT3030, 3031, 8000The ports on your computer, as above.
SITE_URL, ADMIN_URL, API_URLThe local addresses on those portsWhere the browser reaches each app. Set all three when serving the stack on your own domains, such as API_URL=https://api.your-domain.com.
SEED_SAMPLE_DATAtruefalse starts a new volume without the sample data. It matters only on a new volume.
ADMIN_EMAIL, ADMIN_PASSWORD, ADMIN_NAME, ADMIN_WORKSPACEEmptyWith SEED_SAMPLE_DATA=false, your first account, created on the first start; left empty, only the tables are created.

The API container also reads back-end/.env when it exists, so Stripe, mail, the bucket, the assistant's keys and the MCP key are set in one place for both yarn dev and Docker. The compose file wins for the values that differ inside a container: the database path, the upload folder, the port, NODE_ENV=production, the addresses above and demo mode, which it keeps off. The database and the uploads live in the closeline-data volume.

File storage

Deal files, project files, profile pictures and chat attachments are stored on the API's disk under MEDIA_UPLOAD_DIR and served at /media/uploads/…, unless a bucket is set. The brand files and artwork the API serves itself live in public/media/closeline. On a server, point MEDIA_UPLOAD_DIR at persistent storage; with Docker it is in the data volume. A file is at most 10 MB.

To send uploads to a Cloudflare R2 bucket, set all five variables:

The API's .env
R2_ACCESS_KEY_ID=your-r2-access-key-id
R2_SECRET_ACCESS_KEY=your-r2-secret-access-key
R2_ENDPOINT=https://your-account-id.r2.cloudflarestorage.com
R2_BUCKET_NAME=your-bucket-name
R2_PUBLIC_URL=https://your-public-url.r2.dev

Billing

With none of these set, every plan is paid for in the built-in test checkout, which moves no money.

VariableWhat it does
STRIPE_SECRET_KEYStripe Checkout, plan changes on the card on file and the customer portal. A sk_test_ key while you try it.
STRIPE_WEBHOOK_SECRETVerifies POST /api/billing/webhooks/stripe. Without it renewals and failed payments are not recorded.
BILLING_PROVIDERsimulator keeps the test checkout even with a Stripe key.
BILLING_GRACE_DAYSDays a past-due workspace, or one whose trial ended unpaid, may still invite people, 7.

What each plan includes is not an environment variable or a platform setting: it is PLAN_FEATURE_MAP in back-end/src/modules/billing/constants/plans.constants.ts, in the code beside the prices.

Email

The API sends invitations, password resets, billing notices and contact form messages through your SMTP server. Leave SMTP_HOST empty and every message is written to the API's log instead, links included.

The API's .env
SMTP_HOST=smtp.your-provider.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-smtp-user
SMTP_PASSWORD=your-smtp-password
SMTP_FROM=Closeline <no-reply@your-domain.com>
CONTACT_INBOX=sales@your-domain.com

SMTP_FROM is the sender: your product's name and an address on your own domain. Left empty, it is the product's name from the site_name platform setting with no-reply@localhost. CONTACT_INBOX is where the website's contact messages are forwarded; empty keeps them in the database only. Links in a message open the dashboard at DASHBOARD_URL.

Invitations, password resets and billing notices are written in the recipient's language, English or Arabic: the language the account chose, otherwise the workspace's language (for a reset, the language the reset was asked in).

Platform settings

A few settings live in the database rather than in .env, seeded with these values and shared by every workspace:

KeySeeded valueWhat it does
site_nameCloselineThe product's name in what the API writes: email subjects (and the sender when SMTP_FROM is empty), invoice PDFs, the Stripe product, the reports export and the assistant.
trial_days14How many days a new workspace trials. A value that is not a whole number above 0 counts as 14.
signups_enabledtruefalse closes the sign-up page: POST /api/auth/signup answers 403.
maintenance_modefalsetrue closes the product to everyone but platform staff, with a notice; every route answers 503 to the others.
support_emailsupport@closeline.exampleThe support address the assistant gives.
site_tagline, notification_emailCRM for small sales teams, an address at closeline.exampleKept for your own use; the API does not read them.

The dashboard has no page for them. A Platform admin changes one through the API: sign in with POST /api/auth/login, then send one PATCH /api/settings/<key> with the access_token it answers and the value as text, numbers and switches included. It needs the settings.edit permission. A 30-day trial:

Terminal
curl -X PATCH http://localhost:8000/api/settings/trial_days \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"value":"30"}'
ToSend to PATCH /api/settings/...
Close sign-upssignups_enabled with {"value":"false"}
Turn maintenance on, then offmaintenance_mode with {"value":"true"}, later {"value":"false"}. Platform staff keep signing in and working while it is on.
Rename the productsite_name with {"value":"Your Product"}
  • A change applies to the next request, and running yarn seed again keeps every value you set.
  • GET /api/settings (settings.view) lists them all, and GET /api/settings/<key> reads one.
  • The dashboard's sign-up page reads the trial length from the API, so it follows trial_days. The website states it from TRIAL_DAYS in website/src/config/plans.ts: change that with trial_days.

AI assistant keys

Included with your purchase. Sign in to read, or open it in your download.

Turning on the AI assistant: where each provider's key goes and how it is billed.

The MCP server

Included with your purchase. Sign in to read, or open it in your download.

Letting coding agents use the CRM tools: the key, the workspace they read and the endpoint.

Demo mode

Included with your purchase. Sign in to read, or open it in your download.

Running a public demo: the demo switches, per-visitor workspaces and their limits.

Going live

Before you deploy anywhere public, set NODE_ENV=production, your own JWT_SECRET and the real addresses on the API, build each frontend with your API's address, start without the sample data or change the sample passwords, and keep demo mode off.

Stuck on a step?

Find a fix before you start over.

Troubleshooting

Cookie Preferences

We use cookies to enhance your browsing experience, analyze site traffic, and personalize content. By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising.