Prerequisites
- Development environment set up with
direnv allow - Node.js 24+ installed (provided by devenv)
- Docker Compose or Tilt running (for testing)
Using the new-service Command
Thenew-service custom command scaffolds a Node.js microservice with Express.js boilerplate.
Generate the service scaffold
Run the command with your service name and optional port:Examples:This creates:
Service names must be in kebab-case (e.g.,
webhook-service, not WebhookService or webhook_service).node-services/<service-name>/server.js- Express server implementationnode-services/<service-name>/package.json- NPM package definitiondeploy/docker/<service-name>/Dockerfile- Production Dockerfiledeploy/k8s/<service-name>.nix- Kubernetes manifest module
Install dependencies
Navigate to your service directory and install dependencies:Add any additional packages you need:
Implement your service logic
Edit
node-services/<service-name>/server.js to add your routes and business logic.Example structure:Refer to existing services like
node-services/auth-service or node-services/custom-lang-service for complete examples.Add to docker-compose.yml
Add your service to
docker-compose.yml:Unlike Go services, Node.js services typically use HTTP (not h2c) and REST-style path routing.
Update Tiltfile
Add your service to the 2. Add manifest collection:3. Add docker_build configuration:4. Add k8s_resource configuration:
Tiltfile:1. Add to gen-manifests deps:Git add new files (CRITICAL for Nix)
gen-manifests will fail with “file not found” errors.Adding Tests
Create a test file using Vitest:package.json to add test scripts:
Environment Variables
Add environment variables in your service configuration: In docker-compose.yml:Common Issues
gen-manifests fails with 'file not found'
gen-manifests fails with 'file not found'
You forgot to
git add the new files. Nix requires all files to be in the git tree.npm install fails in Docker
npm install fails in Docker
Check your Dockerfile has the correct Node.js version and working directory setup:
Service not accessible via Traefik
Service not accessible via Traefik
Verify the PathPrefix rule in docker-compose.yml:Test directly first without Traefik:
Live reload not working in Tilt
Live reload not working in Tilt
Ensure live_update configuration is correct in Tiltfile:
Next Steps
- Add comprehensive tests with Vitest
- Implement logging and error handling
- Add request validation middleware
- Configure CORS and rate limiting
See Also
- Testing Guide - Learn how to test Node.js services
- Debugging Guide - Debug Node.js services in development
- Adding a Go Service - Add gRPC-based Go services