A simple AI Prompt Web Application built with Node.js that allows users to enter a prompt and receive an AI-generated response using the Groq API.
This project demonstrates how to create a web server using Node.js's built-in http, fs, and path modules without using Express.js.
- ✨ Simple and clean AI prompt interface
- 📝 User can enter any prompt
- 🤖 Generates AI responses using the Groq API
- ⚡ Uses Node.js built-in HTTP server
- 📄 Reads and renders HTML using the
fsmodule - 📁 Handles file paths using the
pathmodule - 🔐 Uses environment variables for API key security
- ❌ Handles API and invalid-request errors
- 🔄 Displays the AI response on the same page
- 📱 Responsive basic UI
- HTML5
- CSS3
- JavaScript
- Node.js
- Node.js
httpmodule - Node.js
fsmodule - Node.js
pathmodule - Fetch API
- Groq API
- ES Modules
- dotenv
The project uses the following main dependency:
dotenvInstall it with:
npm install dotenvFor development, you can also use:
npm install --save-dev nodemonAI-Prompt-Web-Application/
│
├── random.html
├── server.js
├── package.json
├── package-lock.json
├── .env
├── .gitignore
└── README.md
Create a .env file in the root directory:
GROQ_API_KEY=your_groq_api_key_hereNever upload your
.envfile or expose your API key publicly.
Add .env to your .gitignore file:
node_modules/
.envgit clone https://github.com/your-username/AI-Prompt-Web-Application.gitcd AI-Prompt-Web-ApplicationIf package.json already exists:
npm installOtherwise:
npm init -y
npm install dotenvCreate a .env file:
GROQ_API_KEY=your_groq_api_key_hereReplace your_groq_api_key_here with your actual Groq API key.
node server.jsYou should see:
Server running at http://localhost:3000
Visit:
http://localhost:3000
Enter a prompt and click Generate to receive an AI-generated response.
The application follows this basic flow:
User enters a prompt
↓
HTML Form
↓
POST /ai
↓
Node.js HTTP Server
↓
Groq API
↓
AI Generated Response
↓
Render response in HTML
↓
User sees the result
GET /Displays the AI Prompt Generator interface.
POST /aiReceives the user's prompt and sends it to the Groq API.
Example form data:
prompt=Explain JavaScript in simple words
Explain what JavaScript is and why it is important for web development.
The application sends this prompt to the Groq API and displays the generated response on the same page.
The Groq API key is stored in an environment variable instead of directly inside the source code.
GROQ_API_KEY=your_api_keyMake sure .env is included in .gitignore.
This project helped demonstrate:
- Creating a server using Node.js
http - Handling GET and POST requests
- Reading HTML files using
fs - Managing file paths using
path - Processing form data
- Using JavaScript
fetch() - Working with REST APIs
- Handling asynchronous operations with
async/await - Managing API errors
- Using environment variables
- Building a simple AI-powered web application
Possible improvements for this project include:
- 💬 Chat history
- 🎨 Improved UI/UX
- 🌙 Dark mode
- ⏳ Loading indicator
- 📋 Copy AI response button
- 🗑️ Clear response button
- 💾 Save previous prompts and responses
- 📱 More advanced responsive design
- 🔐 Better API error handling
- ⚡ Streaming AI responses
Arifur Rahman
Full Stack / MERN Stack Developer
Interested in building modern web applications with JavaScript, Node.js, React, and related technologies.
If you find this project useful, consider giving the repository a ⭐ on GitHub.