1. Use Case: User this delete api Code: const deleteTodoTask = async (req, res) =>…
- User
User: 1. Use Case: User this delete api Code: const deleteTodoTask = async (req, res) => { const { todoId } = req.params try { // Validate the input if (!todoId) { return { success: false, message: 'Todo ID must be provided.' }; }
// Find and delete the todo by ID const deletedTodo = await Todo.findByIdAndDelete(todoId); // Check if the todo was found and deleted if (!deletedTodo) { return { success: false, message: 'Todo not found.' }; } // Success response return { success: true, message: 'Todo deleted successfully.' }; } catch (error) { // Handle any errors that occur during the process console.error('Error deleting todo:', error); return { success: false, message: 'An error occurred while deleting the todo.' }; }}; User: Description: 1. Install necessary packages: express, helmet, cors, rate-limiter., 2. Set up the server using Express., 3. Configure helmet for security enhancements., 4. Enable cors for universal access., 5. Implement rate-limiter middleware for request rate limiting., 6. Define routes and attach error middleware for handling errors., 7. Set the server to listen on port 4000.
Generate source code based on the description above and respond in the following JSON format ONLY: ```json { "name": "prompt_name", "schema": { "type": "string", "code": "Generated code here" } } ``` IMPORTANT: - Ensure the JSON response is error-free. - Include no additional text or explanations. Respond with the JSON object only.Assistant:
- Assistant
{ "name": "express_app_setup", "schema": { "type": "string", "code": "const express = require('express');\nconst helmet = require('helmet');\nconst cors = require('cors');\nconst rateLimit = require('express-rate-limit');\nconst app = express();\n\n// Security enhancements\napp.use(helmet());\n\n// Enable CORS\napp.use(cors());\n\n// Rate limiter middleware\nconst limiter = rateLimit({\n windowMs: 15 * 60 * 1000, // 15 minutes\n max: 100 // Limit each IP to 100 requests per windowMs\n});\napp.use(limiter);\n\n// Middleware to parse JSON\napp.use(express.json());\n\n// Route for deleting a todo task\napp.delete('/todo/:todoId', deleteTodoTask);\n\n// Error handling middleware\napp.use((err, req, res, next) => {\n console.error(err.stack);\n res.status(500).send({ success: false, message: 'Something went wrong!' });\n});\n\n// Set the server to listen on port 4000\napp.listen(4000, () => {\n console.log('Server is running on port 4000');\n});" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.