Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 1.25 KB

File metadata and controls

62 lines (42 loc) · 1.25 KB

Code Explanation — API server

Express app that exposes POST /api/code-explanation and calls Google Gemini via @google/genai.

Environment

Create .env in this directory:

GEMINI_API_KEY=your_gemini_api_key_here
PORT=3001
FRONTEND_URL=http://localhost:5173
Variable Purpose
GEMINI_API_KEY Required. Gemini / Google AI API key.
PORT HTTP port (if unset, the app defaults to 3002 in server.js).
FRONTEND_URL Allowed origin for CORS (use your Vite dev URL, e.g. http://localhost:5173).

Never commit .env with real secrets.

Run

npm install
npm run dev

The server listens on http://localhost:<PORT>.

API

POST /api/code-explanation

Body (JSON):

{
  "code": "string",
  "language": "string"
}

Success (200):

{
  "explanation": "markdown string",
  "language": "javascript"
}

Error: JSON with an error string. Upstream Gemini failures are parsed so clients can show messages such as model overload (503-style) in a readable form.

Model

Configured in server.js (see MODEL constant). Change there if you switch Gemini models.

See also