As AI becomes more critical in decision-making systems, tracking AI safety incidents is essential. Hereβs a simple RESTful API to log, retrieve, and manage such incidents using Node.js, Express, and MongoDB.
π§ Features
- Log incidents with title, description, and severity.
- Retrieve all or specific incidents.
- Delete incidents.
- Input validation with Joi.
- MongoDB (Mongoose) for data storage.
- Custom error handling.
- CORS support.
π Quick Start
1. Clone & Install
git clone https://github.com/surendergupta/AI-Safety-Incident-Log-Service.git
cd AI-Safety-Incident-Log-Service
npm install
Install required packages:
npm i cors dotenv express http-status joi mongoose path
npm i nodemon --save-dev
2. Setup .env
PORT=5000
MONGO_URI=mongodb://localhost:27017/ai_safety_log_api_db
NODE_ENV=development
3. Run the Server
npm run dev
Server will be live at: http://localhost:5000
π Endpoints
β GET /incidents
Get all logged incidents.
π POST /incidents
{
"title": "System Crash",
"description": "AI failed due to memory leak.",
"severity": "High"
}
Output
π GET /incidents/:id
β DELETE /incidents/:id
π§ Schema
const incidentSchema = new mongoose.Schema({
title: String,
description: String,
severity: { type: String, enum: ["Low", "Medium", "High"] }
}, { timestamps: true });
β Why This Project?
- π¦ Demonstrates validation with Joi.
- π« Handles errors cleanly.
- π¦ Uses scalable document storage (MongoDB).
- π§ͺ Great for API testing, learning, or as a boilerplate.
Check it out π
AI Safety Incident Log Service
Overview
This is a simple RESTful API service built with Node.js, Express.js, and MongoDB to log and manage AI safety incidents.
Flow of the API
Features
- Create, retrieve, and delete AI safety incidents.
- Uses MongoDB for persistent storage.
- MongoDB as the database with Mongoose ORM.
- Request validation using Joi.
- Implements basic validation and error handling.
- API error handling with custom error classes.
- Supports CORS for cross-origin requests.
Prerequisites
- Node.js (>= 14.x recommended)
- MongoDB (running locally or in the cloud, e.g., MongoDB Atlas)
Clone the Repository
git clone https://github.com/surendergupta/AI-Safety-Incident-Log-Service.git
cd AI-Safety-Incident-Log-Service
Install Dependencies
npm install
Install Packages
npm i cors
npm i dotenv --save
npm i express
npm i http-status
npm i joi
npm i mongoose
npm i nodemon --save-dev
npm i path
Set Up Environment
Create a .env file in the project root with:
PORT=5000
MONGO_URI=mongodb://localhost:27017/ai_safety_log_api_db # Update this if using
β¦β¨ Thank you for reading! β¨ I hope this article helped simplify the process and gave you valuable insights. As I continue to explore the ever-evolving world of technology, Iβm excited to share more guides, tips, and updates with you. π Stay tuned for more content that breaks down complex concepts and makes them easier to grasp. Letβs keep learning and growing together! π‘
Found this useful? Give it a β€οΈ or leave a comment with suggestions!
Top comments (0)