A Node.js backend server for the Leafy application, providing RESTful API endpoints for managing gardeners and gardening tips. Built with Express.js and MongoDB.
- Gardeners Management: API endpoints for retrieving gardener information
- Tips Management: Full CRUD operations for gardening tips
- User-specific Tips: Get tips by user email
- Public/Private Tips: Support for public and private tip availability
- Like System: Update likes on tips
- MongoDB Integration: Robust database operations with MongoDB Atlas
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB Atlas
- Middleware: CORS, dotenv
- Deployment: Vercel
- Node.js (v14 or higher)
- MongoDB Atlas account
- Git
-
Clone the repository
git clone <repository-url> cd Leafy-server
-
Install dependencies
npm install
-
Environment Setup Create a
.envfile in the root directory with the following variables:PORT=3000 DB_USER=your_mongodb_username DB_PASS=your_mongodb_password
-
Start the server
npm start
The server will start on http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| GET | /gardeners |
Get all gardeners |
| GET | /active-gardeners |
Get active gardeners (limited to 6) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /tips |
Get all tips |
| GET | /tip/:id |
Get a single tip by ID |
| POST | /tips |
Create a new tip |
| PUT | /tip/:id |
Update a tip |
| PATCH | /tip/:id |
Update tip likes |
| DELETE | /tip/:id |
Delete a tip |
| GET | /my-tips/:email |
Get tips by user email |
| GET | /public-tips |
Get all public tips |
| GET | /home-tips |
Get 6 public tips for home page |
{
_id: ObjectId,
name: String,
email: String,
status: String, // "active" or "inactive"
// ... other fields
}{
_id: ObjectId,
title: String,
content: String,
userEmail: String,
availability: String, // "Public" or "Private"
likes: Number,
// ... other fields
}This project is configured for deployment on Vercel. The vercel.json file contains the necessary configuration for:
- Build settings
- Route handling
- HTTP methods support
-
Install Vercel CLI:
npm i -g vercel
-
Deploy:
vercel
Make sure to set the following environment variables in your deployment platform:
PORT: Server port (default: 3000)DB_USER: MongoDB Atlas usernameDB_PASS: MongoDB Atlas password
npm start: Start the development servernpm test: Run tests (currently not implemented)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
For support and questions, please open an issue in the repository.
Note: Make sure to replace <repository-url> with the actual repository URL when cloning the project.