Welcome to the documentation for the CRON JOB-API! This API is a Backend Developer Job Aplication Assignment with Node.js, implementing CRUD Functions with MySQL and Cron Job Integration.
The CRON JOB-API provides endpoints for managing products through CRUD operations and scheduling tasks using cron jobs.
- Node.js
- Express.js
- TypeScript
- Cron
- Prisma (MySQL ORM)
- Winston (for logging)
- express-async-errors (simplifies error handling in asynchronous routes)
- express-validator (validate request)
- dotenv (for environment variables)
- Helmet
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory:
cd <project_directory>
- Install dependencies:
npm install
or
yarn install
Set up your database connection: Update the database configuration in the .env file with your database credentials:
- Set up your database connection:
DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password
connection string:
DB_URL=mysql://your_username:your_password@localhost:3306/cron_db
Run database migrations:
npx prisma migrate dev
Set up environment variables: Rename .env.example to .env and fill in the required variables.
PORT=<port_number>
DATABASE_URL=<your_database_url>
- Start the application server:
npm start # for production
or
npm run dev # for development
For detailed API documentation and examples, please refer to the Postman Documentation
Products
POST /api/v1/Product: Create a new product.
GET /api/v1/Product: Get all products.
GET /api/v1/Product/:id: Get a product by ID.
PUT /api/v1/Product/:id: Update a product Info.
DELETE /api/v1/Product/:id: Delete a product by ID.
Create a New Product POST /api/v1/Product
Body:
{
"name": "Book",
"price": 500,
"quantity": 10,
"description": "Magic for kids who love to write"
}
Example:
curl --location --request POST 'https://marketplace-uq57.onrender.com/api/v1/Product' \
--data '{
"name":"Book",
"price":500,
"quantity":10,
"description":"Magic for kids who love to write"
}'
**201 CREATED:** Successful creation.
**200 OK:** Successful request.
**404 Not Found:** Resource not found.
**500 Internal Server Error:** Server error.
Errors are returned as JSON objects with a message field describing the error.