{"id":32588427,"url":"https://github.com/dashawk/simple-task-crud","last_synced_at":"2026-07-03T02:03:56.133Z","repository":{"id":307036227,"uuid":"1028073886","full_name":"dashawk/simple-task-crud","owner":"dashawk","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-29T03:27:10.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-29T05:35:29.945Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://backend-one-phi-11.vercel.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dashawk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-29T02:04:43.000Z","updated_at":"2025-07-29T03:27:25.000Z","dependencies_parsed_at":"2025-07-29T05:35:39.966Z","dependency_job_id":"5d60ed1f-0347-45d1-b47a-3c404e7c8665","html_url":"https://github.com/dashawk/simple-task-crud","commit_stats":null,"previous_names":["dashawk/simple-task-crud"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/dashawk/simple-task-crud","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashawk%2Fsimple-task-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashawk%2Fsimple-task-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashawk%2Fsimple-task-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashawk%2Fsimple-task-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashawk","download_url":"https://codeload.github.com/dashawk/simple-task-crud/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashawk%2Fsimple-task-crud/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35069188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-03T02:00:05.635Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-29T23:57:10.227Z","updated_at":"2026-07-03T02:03:56.121Z","avatar_url":"https://github.com/dashawk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js REST API with PostgreSQL\n\nA RESTful API built with Express.js and PostgreSQL for task management.\n\n## Live Demo\n- https://backend-one-phi-11.vercel.app/\n\n## Features\n\n- ✅ **PostgreSQL Database**: Full PostgreSQL integration with connection\n  pooling\n- ✅ **Auto Database Setup**: Automatically creates database and tables on\n  startup\n- ✅ **Task Management**: Complete CRUD operations for tasks\n- ✅ **Raw SQL**: Pure SQL implementation without ORM\n- ✅ **Error Handling**: Comprehensive error handling and logging\n- ✅ **Environment Configuration**: Configurable via environment variables\n\n## Environment Variables\n\nCopy `.env.example` to `.env` and configure:\n\n```env\n# Application Configuration\nAPP_PORT=3000\nAPP_DEBUG=true\nAPI_VERSION=v1\nNODE_ENV=development\nAPP_NAME=tasks-api\n\n# Database Configuration\n# Option 1: Individual connection parameters\nDB_HOST=localhost\nDB_PORT=5432\nDB_USER=postgres\nDB_PASSWORD=your_password_here\nDB_NAME=tasks_db\n\n# Option 2: Connection string (takes precedence if provided)\n# DATABASE_URL=postgres://username:password@localhost:5432/tasks_db\n\n# Database Pool Configuration\nDB_POOL_MAX=10\nDB_IDLE_MS=30000\nDB_CONNECT_MS=5000\n\n# Optional: Admin database URL for automatic database creation\n# DB_ADMIN_URL=postgres://postgres:password@localhost:5432/postgres\n```\n\n## Getting Started\n\n1. **Install Dependencies**\n\n   ```bash\n   npm install\n   ```\n\n2. **Setup Environment**\n\n   ```bash\n   cp .env.example .env\n   # Edit .env with your database credentials\n   ```\n\n3. **Start Development Server**\n   ```bash\n   npm run dev\n   ```\n\nThe application will automatically:\n\n- Connect to PostgreSQL using connection pooling\n- Create the database if it doesn't exist (when `DB_ADMIN_URL` is provided)\n- Create the tasks table and triggers\n- Start the server on http://localhost:3000\n\n## Database Connection Options\n\nThe application supports two ways to configure database connections:\n\n1. **Individual Parameters**: Set `DB_HOST`, `DB_PORT`, `DB_USER`,\n   `DB_PASSWORD`, and `DB_NAME`\n2. **Connection String**: Set `DATABASE_URL` (takes precedence if both are\n   provided)\n\n### Connection Pool Configuration\n\nThe application uses PostgreSQL connection pooling with the following\nconfigurable options:\n\n- `DB_POOL_MAX`: Maximum number of connections in the pool (default: 10)\n- `DB_IDLE_MS`: Idle timeout in milliseconds (default: 30000)\n- `DB_CONNECT_MS`: Connection timeout in milliseconds (default: 5000)\n- `APP_NAME`: Application name for database connections (default: tasks-api)\n\n### Automatic Database Creation\n\nIf you provide a `DB_ADMIN_URL` environment variable, the application can\nautomatically create the target database if it doesn't exist. This is useful for\ndevelopment environments.\n\n## API Endpoints\n\n### Base Information\n\n- **GET** `/` - Get API information and version\n\n### Task Management\n\n#### Get All Tasks\n\n- **GET** `/api/v1/tasks`\n- **Description**: Retrieve all tasks ordered by creation date (newest first)\n- **Response**:\n  ```json\n  {\n    \"success\": true,\n    \"message\": \"Tasks retrieved successfully\",\n    \"tasks\": [...],\n    \"count\": 5\n  }\n  ```\n\n#### Get Single Task\n\n- **GET** `/api/v1/tasks/:taskID`\n- **Description**: Retrieve a specific task by ID\n- **Parameters**:\n  - `taskID` (integer) - The task ID\n- **Response**:\n  ```json\n  {\n    \"success\": true,\n    \"message\": \"Task retrieved successfully\",\n    \"task\": {\n      \"id\": 1,\n      \"title\": \"Sample Task\",\n      \"description\": \"Task description\",\n      \"completed\": false,\n      \"created_at\": \"2024-01-01T00:00:00.000Z\",\n      \"updated_at\": \"2024-01-01T00:00:00.000Z\"\n    }\n  }\n  ```\n\n#### Create New Task\n\n- **POST** `/api/v1/tasks`\n- **Description**: Create a new task\n- **Request Body**:\n  ```json\n  {\n    \"title\": \"Task Title (required, max 255 chars)\",\n    \"description\": \"Task description (optional)\",\n    \"completed\": false\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"success\": true,\n    \"message\": \"Task created successfully\",\n    \"task\": { ... }\n  }\n  ```\n\n#### Update Task\n\n- **PUT** `/api/v1/tasks/:taskID`\n- **Description**: Update an existing task (partial updates supported)\n- **Parameters**:\n  - `taskID` (integer) - The task ID\n- **Request Body** (all fields optional):\n  ```json\n  {\n    \"title\": \"Updated Title\",\n    \"description\": \"Updated description\",\n    \"completed\": true\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"success\": true,\n    \"message\": \"Task updated successfully\",\n    \"task\": { ... }\n  }\n  ```\n\n#### Delete Task\n\n- **DELETE** `/api/v1/tasks/:taskID`\n- **Description**: Delete a specific task\n- **Parameters**:\n  - `taskID` (integer) - The task ID\n- **Response**:\n  ```json\n  {\n    \"success\": true,\n    \"message\": \"Task deleted successfully\",\n    \"task\": { ... }\n  }\n  ```\n\n### Error Responses\n\nAll endpoints return consistent error responses:\n\n```json\n{\n  \"success\": false,\n  \"message\": \"Error description\"\n}\n```\n\n**Common HTTP Status Codes:**\n\n- `200` - Success\n- `201` - Created (for POST requests)\n- `400` - Bad Request (validation errors)\n- `404` - Not Found (task doesn't exist)\n- `500` - Internal Server Error\n\n## Database Functions\n\nThe database module exports the following functions:\n\n```javascript\nimport {\n  pool,\n  query,\n  withTransaction,\n  createDatabaseIfNotExists,\n  ensureSchema,\n  closeDatabase\n} from './src/config/database.js'\n\n// Execute parameterized queries\nconst result = await query('SELECT * FROM tasks WHERE id = $1', [taskId])\n\n// Use transactions for multiple operations\nconst result = await withTransaction(async (client) =\u003e {\n  await client.query('INSERT INTO tasks (title) VALUES ($1)', ['Task 1'])\n  await client.query('INSERT INTO tasks (title) VALUES ($1)', ['Task 2'])\n  return { success: true }\n})\n\n// Optional: Create database if it doesn't exist (requires DB_ADMIN_URL)\nawait createDatabaseIfNotExists()\n\n// Optional: Ensure schema exists (for development)\nawait ensureSchema()\n\n// Close database connection\nawait closeDatabase()\n```\n\n### Transaction Support\n\nThe `withTransaction` helper automatically handles BEGIN/COMMIT/ROLLBACK\noperations:\n\n```javascript\ntry {\n  const result = await withTransaction(async (client) =\u003e {\n    // All queries here are part of the same transaction\n    const task = await client.query(\n      'INSERT INTO tasks (title) VALUES ($1) RETURNING *',\n      ['New Task']\n    )\n    await client.query('UPDATE tasks SET completed = true WHERE id = $1', [\n      task.rows[0].id\n    ])\n    return task.rows[0]\n  })\n  console.log('Transaction completed:', result)\n} catch (error) {\n  console.error('Transaction failed:', error)\n  // Rollback was handled automatically\n}\n```\n\n## Deployment to Vercel\n\nThis application is configured for deployment to Vercel. Follow these steps:\n\n### Prerequisites\n\n1. **Database Setup**: You'll need a production PostgreSQL database. Options\n   include:\n   - [Vercel Postgres](https://vercel.com/docs/storage/vercel-postgres)\n   - [Supabase](https://supabase.com/)\n   - [Neon](https://neon.tech/)\n   - [Railway](https://railway.app/)\n   - [PlanetScale](https://planetscale.com/) (MySQL alternative)\n\n### Deployment Steps\n\n1. **Install Vercel CLI** (if not already installed):\n\n   ```bash\n   npm install -g vercel\n   ```\n\n2. **Login to Vercel**:\n\n   ```bash\n   vercel login\n   ```\n\n3. **Deploy to Vercel**:\n\n   ```bash\n   vercel\n   ```\n\n4. **Set Environment Variables** in Vercel Dashboard:\n\n   - Go to your project in Vercel Dashboard\n   - Navigate to Settings → Environment Variables\n   - Add the following variables:\n\n   ```env\n   NODE_ENV=production\n   API_VERSION=v1\n   APP_NAME=tasks-api\n   DATABASE_URL=your_production_database_url_here\n   ```\n\n   **Important**: Make sure your `DATABASE_URL` points to your production\n   database.\n\n### Vercel Configuration\n\nThe project includes:\n\n- `vercel.json` - Vercel deployment configuration\n- `api/index.js` - Serverless function entry point\n- `.vercelignore` - Files to exclude from deployment\n\n### Database Considerations\n\n- The application automatically handles SSL connections for production databases\n- Make sure your production database allows connections from Vercel's IP ranges\n- Consider using connection pooling services like PgBouncer for better\n  performance\n\n### Environment Variables for Production\n\n```env\nNODE_ENV=production\nAPI_VERSION=v1\nAPP_NAME=tasks-api\nDATABASE_URL=postgres://username:password@host:port/database?sslmode=require\n```\n\n### Testing the Deployment\n\nAfter deployment, test your API endpoints:\n\n- `GET https://your-app.vercel.app/` - Should return API information\n- `GET https://your-app.vercel.app/api/v1/tasks` - Should return tasks (empty\n  array initially)\n\n### Troubleshooting\n\n1. **Database Connection Issues**:\n\n   - Verify your `DATABASE_URL` is correct\n   - Ensure your database allows external connections\n   - Check that SSL is properly configured\n\n2. **Function Timeout**:\n\n   - Vercel functions have a 10-second timeout on Hobby plan\n   - Consider upgrading to Pro plan for longer timeouts\n\n3. **Cold Starts**:\n   - First request after inactivity may be slower\n   - This is normal for serverless functions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashawk%2Fsimple-task-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashawk%2Fsimple-task-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashawk%2Fsimple-task-crud/lists"}