.env file in the repository root. In production, inject them through your host’s environment or secret manager.
When
NODE_ENV is set to production, the backend skips loading .env via dotenv. All variables must be present in the environment before the process starts.Backend variables
Create a.env file in the repository root (the same directory as app.js).
Database
MongoDB connection string. Used by Mongoose to connect to your database on startup.For MongoDB Atlas, copy the connection string from Database → Connect → Drivers. Replace
<password> with your actual password and optionally append a database name.AI services
Platform-default OpenAI API key. Used for:
- Embeddings —
text-embedding-ada-002model, called when a professor adds lecture videos - Chat completions —
gpt-3.5-turbo-16kmodel, called on every student question
Pinecone API key. Used to read and write lecture embeddings in the vector index.The index name is hardcoded as
courser in classes/CourserAIAssistant.js. You must create an index with that name in your Pinecone project before starting the backend. See Self-hosting overview for index creation settings.Obtain your key from the Pinecone console under API Keys.Authentication
Secret key used to sign and verify JWT tokens for professor sessions. Set this to a long, random string — at least 32 characters.Generate a suitable value with:
File storage
Cloudinary connection URL, used for uploading chatbot background images. This is the all-in-one credential URL that Cloudinary provides in your dashboard.Find it in the Cloudinary console under Dashboard → API Keys.Alternatively, you can configure Cloudinary using individual variables (
CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET) if your Cloudinary SDK version supports it, but CLOUDINARY_URL is the format used in the current source.Server
Port the Express server listens on. Optional — defaults to
8000 if not set.Runtime environment. Set to
production in production deployments.When set to production, the backend skips calling require('dotenv').config(), so it will not read a .env file. All variables must already be in the environment.Firebase configuration
Firebase Auth is configured differently from the variables above. The Firebase client config is currently hardcoded as an object inendpoints/auth.js:
Firebase client config values (API key, project ID, etc.) are designed to be public — they identify your Firebase project but do not grant privileged access on their own. Security is enforced by Firebase Authentication rules and your backend’s JWT verification. That said, use your own project’s config in any self-hosted deployment so that accounts belong to your project.
Frontend variables
Create a.env.local file in the client directory for local development. In production, set these through your hosting provider.
Full base URL of your backend API, without a trailing slash. The Next.js frontend uses this to construct all API requests.Because this variable is prefixed with
NEXT_PUBLIC_, Next.js inlines it into the browser bundle at build time. Changing it requires a rebuild.Sample .env file
Copy this template to the repository root as.env and fill in your values:
.env
client/.env.local:
client/.env.local
Variable summary
| Variable | Required | Default | Used in |
|---|---|---|---|
MONGO_URI | Yes | — | app.js |
OPENAI_API_KEY | Yes | — | classes/CourserAIAssistant.js |
PINECONE_API_KEY | Yes | — | classes/CourserAIAssistant.js |
JWT_PRIVATE_KEY | Yes | — | middleware.js |
CLOUDINARY_URL | Yes | — | endpoints/course.js |
PORT | No | 8000 | app.js |
NODE_ENV | No | development | app.js |
NEXT_PUBLIC_API_URL | Yes | — | Next.js frontend |