A Node.js/Express backend server for Rohan's website that provides API endpoints for various integrations.
- 🚀 Express Server: Simple and fast web server
- 🔐 Environment Variables: Secure API key management with
.envfile - 🌐 CORS Configuration: Properly configured for local development
- 🤖 Gemini API Integration: Proxy endpoint for AI-powered features
- 📊 Health Check: Server status monitoring
- Node.js 18+
- npm or yarn
- Install dependencies:
npm install- Set up environment variables:
cp .env .env.local- Edit
.env.localand add your API keys:
GEMINI_API_KEY=your_actual_gemini_api_key_hereStart the development server:
npm run devOr start in production mode:
npm startThe server will run on http://localhost:3000
- GET
/health - Returns server status and timestamp
- POST
/api/gemini - Body:
{ "prompt": "Your prompt here" } - Returns AI-generated response
- GET
/api/posts - Returns blog posts data
The frontend (index.html) has been updated to use the backend API instead of making direct API calls. This provides:
- Security: API keys are stored server-side
- CORS Handling: Proper cross-origin request handling
- Error Handling: Centralized error management
- Rate Limiting: Can be easily added to the backend
.
├── server.js # Main Express server
├── package.json # Project dependencies
├── .env # Environment variables template
├── .env.local # Your actual environment variables (create this)
├── main.js # Frontend JavaScript
├── index.html # Main HTML file
└── README.md # This file
| Variable | Description | Required |
|---|---|---|
PORT |
Server port (default: 3000) | No |
NODE_ENV |
Environment mode | No |
GEMINI_API_KEY |
Google Gemini API key | Yes |
CORS_ORIGIN |
Allowed CORS origins | No |
The server is configured to allow requests from:
http://localhost:3000http://127.0.0.1:5500http://localhost:5500
You can modify these in the .env file or add more origins as needed.
- Start the backend server:
npm run dev - Open
index.htmlin your browser or serve it with a local server - The frontend will automatically connect to the backend API
- Keep your
.env.localfile secure and never commit it to version control - The
.envfile is a template - replace placeholder values with real API keys - API keys are handled server-side for security
In development mode (NODE_ENV=development), the server provides detailed error messages. In production, error details are hidden for security.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request