Simple web chatbot using Google Generative AI (Gemini) with an Express backend and a vanilla JS frontend that renders markdown safely.
- Chat with Gemini AI in real time.
- Node.js v16+
- NPM
- Google Gemini API key
- Clone the repository:
git clone https://github.com/akmalscript/gemini-ai-chatbot.git cd gemini-ai-chatbot - Install dependencies:
npm init -y npm install express cors dotenv @google/generative-ai
- Create a .env file in the root directory:
GEMINI_API_KEY=your-gemini-api-key
- Start the server:
node index.js
- Open the chatbot in your browser
http://loocalhost:3000
- Type your message in the input field.
- Press Send.
- Gemini AI will generate a response and display it in the chatbox with proper Markdown formatting.
Example conversation:
User: Explain recursion in simple terms.
Gemini AI: Recursion is when a function calls itself to solve a smaller piece of a problem...
├── public/ # Frontend assets
│ ├── index.html # Frontend structure
│ ├── script.js # Handles chat logic and rendering
│ └── style.css # Styles for chat UI
├── index.js # Backend Express server with Gemini API integration
├── .env # API key configuration (not included in repo)
├── .gitignore # Ignore node_modules, .env, etc.
├── chatbot-preview.png # Preview for documentation
├── package.json # Project metadata and dependencies
├── package-lock.json # Dependency lock file
└── README.md # Project documentation
- This server runs on port 3000 by default.
- Ensure your .env file contains a valid GEMINI_API_KEY.