https://github.com/ramxcodes/advice-me-ram-backend
The backend of Advice Me Ram is a RESTful API built with Node.js, Express, and MongoDB. This API enables users to contribute advice and retrieve random pieces of advice from a database. The backend is designed to handle requests efficiently and provides endpoints for creating and fetching advice.
https://github.com/ramxcodes/advice-me-ram-backend
backend backend-api cronjob full-stack mern mongodb vercel
Last synced: 27 days ago
JSON representation
The backend of Advice Me Ram is a RESTful API built with Node.js, Express, and MongoDB. This API enables users to contribute advice and retrieve random pieces of advice from a database. The backend is designed to handle requests efficiently and provides endpoints for creating and fetching advice.
- Host: GitHub
- URL: https://github.com/ramxcodes/advice-me-ram-backend
- Owner: ramxcodes
- Created: 2024-11-01T11:38:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-03T11:29:59.000Z (over 1 year ago)
- Last Synced: 2025-03-30T12:14:13.159Z (about 1 year ago)
- Topics: backend, backend-api, cronjob, full-stack, mern, mongodb, vercel
- Language: JavaScript
- Homepage: https://advice-me-ram.vercel.app/
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Advice Me Ram Backend ππ‘
The backend of **Advice Me Ram** is a RESTful API built with Node.js, Express, and MongoDB. This API enables users to contribute advice and retrieve random pieces of advice from a database. The backend is designed to handle requests efficiently and provides endpoints for creating and fetching advice.
π **Live Site**: [https://advice-me-ram.vercel.app/](https://advice-me-ram.vercel.app/)
## Features β¨
- **Post Advice**: Submit advice with an authorβs name to store in the database.
- **Get Random Advice**: Fetch a random piece of advice from the database.
- **Error Handling**: Robust error handling for database and server errors.
- **Modular Structure**: Organized codebase with separate routes, controllers, and models for scalability.
## Technologies π οΈ
- **Node.js**: JavaScript runtime for server-side code.
- **Express**: Fast and minimalist web framework for Node.js.
- **MongoDB**: NoSQL database for storing advice data.
- **Mongoose**: ODM for MongoDB to define models and schemas.
## API Endpoints π¬
### 1. **Post Advice**
- **URL**: `/sendadvice`
- **Method**: `POST`
- **Description**: Accepts an advice text and author name, then saves it to the database.
- **Body Parameters**:
- `advice`: (String) The advice content.
- `author`: (String) The name of the advice author.
- **Example Request**:
```json
{
"advice": "Stay positive!",
"author": "John Doe"
}
```
- **Example Response**:
```json
{
"message": "Advice saved successfully!"
}
```
### 2. **Get Random Advice**
- **URL**: `/getadvice`
- **Method**: `GET`
- **Description**: Returns a random piece of advice from the database.
- **Example Response**:
```json
{
"advice": "Don't forget to smile!",
"author": "Jane Smith"
}
```
## Getting Started π
### Prerequisites
- **Node.js** (>=12.x recommended)
- **MongoDB**: A running MongoDB instance (local or cloud-based).
### Installation
1. Clone the repository:
```bash
git clone https://github.com/ramxcodes/Advice-me-ram-backend.git
cd advice-me-ram-backend
```
2. Install dependencies:
```bash
npm install
```
3. Create a `.env` file in the root directory and add the following variables:
```bash
PORT=5000
MONGODB_URI=your_mongodb_connection_string
```
4. Start the server:
```bash
npm start
```
The server should now be running at `http://localhost:5000`.
## Folder Structure π
- **`/models`**: Mongoose schemas for defining the `Advice` model.
- **`/controllers`**: Contains logic for handling requests and responses.
- **`/routes`**: Defines routes for posting and fetching advice.
## Error Handling π«
- If a required field is missing or thereβs a database error, the server will respond with a `500` status and an appropriate error message.