Skip to content

Developer Setup Guide

This guide provides comprehensive setup instructions for the WorkerSQL development environment - a MySQL-compatible edge database platform built on Cloudflare Workers.

  • Node.js: v18.0.0 or higher (Download)
  • npm: v8.0.0 or higher (comes with Node.js)
  • Git: Latest version (Download)
  • Python: v3.8+ (for security scanning tools)
  • VS Code: Recommended IDE (Download)
  • Cloudflare account with Workers enabled
  • Workers Paid plan (required for Durable Objects)
  • API Token with the following permissions:
    • Cloudflare Workers:Edit
    • Account:Read
    • Zone:Read
Terminal window
git clone https://github.com/healthfees-org/workersql.git
cd workersql
Terminal window
# Install Node.js dependencies
npm install
# Install Python dependencies for security scanning
python -m pip install --user pre-commit bandit
Terminal window
# Install pre-commit hooks
npm run prepare
# Test pre-commit installation
pre-commit run --all-files
Terminal window
# Install Wrangler CLI globally (if not already installed)
npm install -g wrangler
# Authenticate with Cloudflare
wrangler auth login
# Copy and configure wrangler.toml
cp wrangler.toml.template wrangler.toml

Create a .env.local file:

Terminal window
# Copy environment template
cp .env.example .env.local
# Edit with your values
ENVIRONMENT=development
LOG_LEVEL=debug
MAX_SHARD_SIZE_GB=1
CACHE_TTL_MS=300000
CACHE_SWR_MS=600000
SHARD_COUNT=4
Terminal window
# Set JWT secret for authentication
wrangler secret put JWT_SECRET
# Set encryption keys
wrangler secret put ENCRYPTION_KEY_PRIMARY
wrangler secret put ENCRYPTION_KEY_SECONDARY
Terminal window
# TypeScript compilation
npm run build
# Watch mode for development
npm run build -- --watch
Terminal window
# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:coverage
# Run tests in watch mode
npm run test:watch
Terminal window
# Start local development server
npm run dev
# Test local deployment
curl -X POST http://localhost:8787/query \
-H "Content-Type: application/json" \
-H "Authorization: Bearer test-token-12345" \
-d '{"sql": "SELECT 1 as test"}'
Terminal window
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Check formatting
npm run format:check
# Run security scans
npm run security:check
# Complete workflow check
npm run workflow:check

Install these recommended extensions:

{
"recommendations": [
"ms-vscode.vscode-typescript-next",
"esbenp.prettier-vscode",
"ms-vscode.vscode-eslint",
"bradlc.vscode-tailwindcss",
"ms-python.python",
"ms-python.bandit"
]
}

Add to your .vscode/settings.json:

{
"typescript.preferences.strictFunctionTypes": true,
"typescript.preferences.strictNullChecks": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.workingDirectories": ["src", "tests"]
}
  • Located in tests/unit/
  • Use Jest with ts-jest transformer
  • Mock Cloudflare Workers environment
  • Focus on individual service logic
  • Located in tests/integration/
  • Use Miniflare for Cloudflare Workers simulation
  • Test service interactions
  • Validate cache and queue behaviors
  • Located in tests/e2e/
  • Test complete workflows
  • Validate API contracts
  • Performance benchmarking
  • Located in tests/browser/
  • Use Playwright for browser automation
  • Test client SDK functionality
  • Cross-browser compatibility
Terminal window
# Deploy to development environment
wrangler deploy --env development
# View deployment logs
wrangler tail
Terminal window
# Deploy to staging environment
wrangler deploy --env staging
# Run smoke tests against staging
npm run test:smoke -- --env=staging
Terminal window
# Deploy to production (requires approval)
wrangler deploy --env production
# Monitor production deployment
wrangler tail --env production
Terminal window
# Clear TypeScript cache
npx tsc --build --clean
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
Terminal window
# Update test snapshots
npm test -- --updateSnapshot
# Run tests with verbose output
npm test -- --verbose
# Debug specific test
npm test -- --testNamePattern="test name"
Terminal window
# Re-authenticate
wrangler auth logout
wrangler auth login
# Clear Wrangler cache
rm -rf ~/.wrangler/cache
Terminal window
# Update pre-commit hooks
pre-commit autoupdate
# Skip hooks temporarily (emergency only)
git commit --no-verify
  • Use --testPathPattern to run specific tests
  • Implement test parallelization
  • Mock external dependencies
  • Use --incremental flag with TypeScript
  • Configure path mapping correctly
  • Exclude unnecessary files from compilation
  • Verify JWT_SECRET is set correctly
  • Check token expiration times
  • Validate issuer and audience claims
  • Update gateway CORS configuration
  • Check request headers and methods
  • Validate origin whitelist
  • Follow TypeScript strict mode guidelines
  • Use ESLint and Prettier configurations
  • Write comprehensive JSDoc comments
  • Follow security best practices
  1. Create feature branch from main
  2. Implement changes with tests
  3. Run npm run workflow:check
  4. Submit PR with description
  5. Address review feedback
  6. Merge after approval
  • Never commit secrets or credentials
  • Use Wrangler secrets for sensitive data
  • Follow OWASP security guidelines
  • Run security scans before commits

Last updated: September 1, 2025 Version: 1.0.0