gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Untitled conversation
- User
{description:Set up an Express server to listen on port 4000., Implement rate limiting using the 'express-rate-limit' package., Use 'helmet' for security headers., Enable CORS for universal access using the 'cors' package., Implement error handling middleware for routing errors. }
codeAnalyse above object generate source code for description and send response as only a json_object {"name": "prompt_name", "schema": { "type": "string", "code":"genarted code" "require":"extracted external modules or libraries like const bcrypt = require('bcrypt');" } }
- Assistantjson
{ "name": "ExpressServerSetup", "schema": { "type": "string", "code": "const express = require('express');\nconst rateLimit = require('express-rate-limit');\nconst helmet = require('helmet');\nconst cors = require('cors');\n\nconst app = express();\nconst PORT = 4000;\n\n// Implement rate limiting\nconst limiter = rateLimit({\n windowMs: 15 * 60 * 1000, // 15 minutes\n max: 100 // Limit each IP to 100 requests per windowMs\n});\n\napp.use(limiter);\napp.use(helmet()); // Secure app by setting various HTTP headers\napp.use(cors()); // Enable CORS for all requests\n\n// Sample route\napp.get('/', (req, res) => {\n res.json({ message: 'Welcome to the Express server!' });\n});\n\n// Error handling middleware\napp.use((err, req, res, next) => {\n console.error(err.stack);\n res.status(500).json({ error: 'Something went wrong!' });\n});\n\napp.listen(PORT, () => {\n console.log(`Server is running on http://localhost:${PORT}`);\n});", "require": [ "express", "express-rate-limit", "helmet", "cors" ] } }