Dataset Viewer
Auto-converted to Parquet Duplicate
prompt
stringclasses
1 value
tests
stringclasses
1 value
I need you to create a full Express.js server in JavaScript with the following specifications: 1. **Server Setup** - Use Express.js framework. - Run the server on host `0.0.0.0` and port `5000`. - Ensure all dependencies (`express`, `sqlite3`, `jsonwebtoken`, `bcrypt` or similar) are installed and included in `package.json`. Don't set a version number, just list the names 2. **Routes** - **GET /** - Respond with status 200 and plain text: `"Hello, World!"`. - **GET /health** - Respond with status 200 and JSON: `{ "status": "healthy" }`. - **POST /register** - Accept JSON payload: `{ "username": "<string>", "password": "<string>" }`. - Hash the password using bcrypt (or similar secure hashing). - Store the user credentials in an SQLite3 database (`users` table). - Return JSON with a success message and optionally a JWT token. - **POST /login** - Accept JSON payload: `{ "username": "<string>", "password": "<string>" }`. - Validate credentials against the SQLite3 database. - If valid, return a JWT token in JSON. - If invalid, return status 401 with a JSON error message. Ensure that the server runs using npm start Run the server after implementation using exec to ensure it starts correctly.
{"info": {"name": "Express Server Tests", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"}, "variable": [{"key": "BASE_URL", "value": "http://host.docker.internal:5000"}, {"key": "USERNAME", "value": ""}, {"key": "PASSWORD", "value": "testing43215"}, {"key": "TOKEN", "value": ""}], "item": [{"name": "Generate Random Username", "event": [{"listen": "prerequest", "script": {"exec": ["let uname = 'user_' + Math.random().toString(36).substring(2,10);", "pm.collectionVariables.set('USERNAME', uname);", "console.log('Generated username:', uname);"]}}, {"listen": "test", "script": {"exec": ["pm.test('Username generated', function(){", " pm.expect(pm.collectionVariables.get('USERNAME')).to.be.a('string');", "});"]}}], "request": {"method": "GET", "url": "{{BASE_URL}}/"}}, {"name": "GET /", "request": {"method": "GET", "url": "{{BASE_URL}}/"}, "event": [{"listen": "test", "script": {"exec": ["pm.test('Status is 200', function(){", " pm.response.to.have.status(200);", "});", "", "pm.test('Body contains Hello, World!', function(){", " pm.expect(pm.response.text()).to.include('Hello, World');", "});"]}}]}, {"name": "GET /health", "request": {"method": "GET", "url": "{{BASE_URL}}/health"}, "event": [{"listen": "test", "script": {"exec": ["pm.test('Status is 200', function(){", " pm.response.to.have.status(200);", "});", "", "pm.test('Returns JSON', function(){", " pm.response.to.be.json;", "});", "", "let json = pm.response.json();", "pm.test('status is healthy', function(){", " pm.expect(json.status).to.eql('healthy');", "});"]}}]}, {"name": "POST /register", "request": {"method": "POST", "header": [{"key": "Content-Type", "value": "application/json"}], "body": {"mode": "raw", "raw": "{\n \"username\": \"{{USERNAME}}\",\n \"password\": \"{{PASSWORD}}\"\n}"}, "url": "{{BASE_URL}}/register"}, "event": [{"listen": "test", "script": {"exec": ["pm.test('Register returns 200 or 201', function(){", " pm.expect([200,201]).to.include(pm.response.code);", "});", "", "pm.test('Response is JSON', function(){", " pm.response.to.be.json;", "});", "", "let json = pm.response.json();", "", "if (json.token) {", " pm.collectionVariables.set('TOKEN', json.token);", "}"]}}]}, {"name": "POST /login", "request": {"method": "POST", "header": [{"key": "Content-Type", "value": "application/json"}], "body": {"mode": "raw", "raw": "{\n \"username\": \"{{USERNAME}}\",\n \"password\": \"{{PASSWORD}}\"\n}"}, "url": "{{BASE_URL}}/login"}, "event": [{"listen": "test", "script": {"exec": ["pm.test('Status is 200', function(){", " pm.response.to.have.status(200);", "});", "", "pm.test('Response is JSON', function(){", " pm.response.to.be.json;", "});", "", "let json = pm.response.json();", "", "pm.test('Contains token field', function(){", " pm.expect(json).to.have.property('token');", "});", "", "pm.collectionVariables.set('TOKEN', json.token);"]}}]}]}
README.md exists but content is empty.
Downloads last month
6