This directory contains both REST and gRPC implementations of the Task Management API in JavaScript using Node.js.
javascript/
├── rest/
│ ├── server/ # Express.js REST API server
│ └── client/ # REST API client
└── grpc/
├── server/ # gRPC server implementation
└── client/ # gRPC client implementation
- Node.js 18.0 or higher
- npm 8.0 or higher
cd rest/server
npm install
npm start # Production mode
npm run dev # Development mode with auto-reloadThe REST API server will run on http://localhost:8080
cd rest/client
node client.jsGET /health- Health checkGET /api/v1/tasks- List all tasksGET /api/v1/tasks/:id- Get a specific taskPOST /api/v1/tasks- Create a new taskPUT /api/v1/tasks/:id- Update a taskPATCH /api/v1/tasks/:id/status- Update task statusDELETE /api/v1/tasks/:id- Delete a task
cd grpc/server
npm install
npm start # Production mode
npm run dev # Development mode with auto-reloadThe gRPC server will run on localhost:50051
cd grpc/client
npm install
npm startListTasks- Server streaming method to list tasksGetTask- Unary call to get a single taskCreateTask- Unary call to create a taskUpdateTask- Unary call to update a taskDeleteTask- Unary call to delete a taskWatchTasks- Bidirectional streaming for real-time updates
# Terminal 1 - Start REST server
cd rest/server && npm start
# Terminal 2 - Start gRPC server
cd grpc/server && npm start
# Terminal 3 - Run tests
cd rest/client && node client.js
cd grpc/client && node client.js# Build the image
docker build -t task-api-js .
# Run the container
docker run -p 8080:8080 -p 50051:50051 task-api-js- Express.js middleware pipeline
- Request validation
- Error handling middleware
- CORS configuration
- Security headers with Helmet
- Request logging with Morgan
- Async/await patterns
- RESTful resource design
- Protocol Buffers integration
- Server streaming (ListTasks)
- Unary calls (Get, Create, Update, Delete)
- Bidirectional streaming (WatchTasks)
- Error handling with gRPC status codes
- Real-time event notifications
The gRPC implementation typically shows:
- 30-40% lower latency for simple operations
- 50-60% smaller payload sizes
- Better performance for streaming operations
- Type safety through Protocol Buffers
In production, you should:
- Enable TLS/SSL for both REST and gRPC
- Implement proper authentication (JWT, OAuth2)
- Add rate limiting
- Validate and sanitize all inputs
- Use environment variables for configuration
- Implement proper logging and monitoring
# Find process using port 8080
lsof -i :8080
# Kill the process
kill -9 <PID>Ensure you're using Node.js 18+ which has better ESM support:
node --version # Should be v18.0.0 or higherCheck that the proto file path is correct and the gRPC server is running:
# Test gRPC server with grpcurl
grpcurl -plaintext localhost:50051 list- Add database persistence (MongoDB, PostgreSQL)
- Implement authentication and authorization
- Add comprehensive test suite
- Set up CI/CD pipeline
- Add OpenTelemetry for observability
- Implement caching layer
- Add WebSocket support for REST API real-time updates