A simple, real AI chatbot: a web chat widget backed by a small Node.js server that talks to a large language model (Claude or ChatGPT).
This is intentionally small and readable. It demonstrates three things that matter for real chatbot work:
- Model-agnostic design — the LLM lives behind one interface (
llm.js). Switching Claude ↔ ChatGPT is a one-line change in.env, no rewrite. - Persistent sessions — the conversation is saved in the browser, so it does not reset on page refresh or tab switch.
- A clean backend boundary — the browser never sees your API key; it only
talks to your own
/api/chatendpoint.
Pick ONE:
- Claude (recommended): https://console.anthropic.com → Settings → API Keys
- ChatGPT: https://platform.openai.com/api-keys
Both have low-cost / free trial credit. A demo costs cents to run.
# install Node.js 18+ first: https://nodejs.org
npm install
cp .env.example .env # on Windows PowerShell: copy .env.example .envOpen .env and paste your real API key. Leave LLM_PROVIDER=anthropic for Claude,
or set it to openai for ChatGPT.
npm startOpen http://localhost:3000 — you now have a working chatbot.
Easiest free option: Render (https://render.com)
- Push this folder to a GitHub repo.
- On Render: New → Web Service → connect the repo.
- Build command:
npm install— Start command:npm start - Add your environment variables (
LLM_PROVIDER,ANTHROPIC_API_KEY,ANTHROPIC_MODEL) under the service's Environment tab. - Deploy. Render gives you a public
https://...onrender.comURL.
That URL is your real, shareable demo link.
Browser (public/index.html)
│ POST /api/chat { messages: [...] }
▼
server.js ──► llm.js ──► Claude or ChatGPT API
▲ │
└──────── { reply } ◄──────────┘
public/index.html— the chat UI. Stores history inlocalStorage(persistent session).server.js— serves the page and the/api/chatendpoint.llm.js— the model-agnostic layer. This is where Claude vs ChatGPT is decided.