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": "todo_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 mongoose = require('mongoose');\n\nconst app = express();\nconst PORT = 4000;\n\n// Connect to MongoDB (replace 'your_connection_string' with your actual connection string)\nmongoose.connect('your_connection_string', { useNewUrlParser: true, useUnifiedTopology: true })\n\t.then(() => console.log('MongoDB connected'))\n\t.catch(err => console.error('MongoDB connection error:', err));\n\n// Middleware setup\napp.use(helmet());\napp.use(cors());\n\n// Rate limiter middleware to limit requests to 100 per 15 minutes\nconst limiter = rateLimit({\n windowMs: 15 * 60 * 1000,\n max: 100\n});\napp.use(limiter);\n\n// Sample Todo route\napp.delete('/todos/:todoId', deleteTodoTask);\n\n// Error handling middleware\napp.use((err, req, res, next) => {\n console.error(err.stack);\n res.status(500).send('Something broke!');\n});\n\n// Start server\napp.listen(PORT, () => {\n console.log(`Server running on port ${PORT}`);\n});" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.