A private NPM registry powered by Cloudflare Workers, R2, and D1. This registry allows you to host and manage private NPM packages with authentication and access control.
- Private Package Hosting: Securely host your private NPM packages
- Token-based Authentication: Control access with scoped tokens
- Cloudflare Infrastructure: Built on Workers, R2 for storage, and D1 for metadata
- Custom Domain Support: Available at
npm.coalescelabs.ai - Fallback to Public Registry: Seamlessly falls back to npmjs.org for public packages
- CI/CD Ready: Automated deployment with GitHub Actions
- Cloudflare account with Workers, R2, and D1 enabled
- Domain configured in Cloudflare (for custom domain)
- Node.js 20+ and pnpm
- Wrangler CLI installed (
npm install -g wrangler)
git clone https://github.com/coalesce-labs/npm-repo.git
cd npm-repo
pnpm install- Go to your GitHub repository settings
- Add these secrets under Settings > Secrets and variables > Actions:
CLOUDFLARE_API_TOKEN: Your Cloudflare API tokenCLOUDFLARE_ACCOUNT_ID: Your Cloudflare account ID
The repository uses GitHub Actions for automated deployment:
- Push to
main: Deploys to staging environment - Push to
production: Deploys to production environment
# Deploy to production
git checkout -b production
git push origin productionIf you need to set up the infrastructure manually:
wrangler r2 bucket create coalesce-labs-npm-repositorywrangler d1 create npflared-db
# Note the database ID returnedEdit apps/api/wrangler.production.toml with your database ID:
[[d1_databases]]
binding = "DB"
database_name = "npflared-db"
database_id = "YOUR_DATABASE_ID_HERE"cd apps/api
wrangler d1 execute npflared-db --file=migrations/0000_bright_mercury.sqlwrangler deploy --env productionCreate a .npmrc file in your project:
@your-scope:registry=https://npm.coalescelabs.ai
//npm.coalescelabs.ai/:_auth=YOUR_AUTH_TOKENnpm publish --registry=https://npm.coalescelabs.ainpm install @your-scope/package-namewrangler d1 execute npflared-db --command "SELECT * FROM token"# Generate token
NEW_TOKEN=$(openssl rand -hex 32)
# Add to database
wrangler d1 execute npflared-db --command "INSERT INTO token (token, name, scopes) VALUES ('$NEW_TOKEN', 'developer-name', '[\"read\", \"write\"]')"["read"]: Can only install packages["read", "write"]: Can install and publish packages
The infrastructure is defined as code. To backup:
- Code: Already in Git
- Database: Export D1 data
wrangler d1 execute npflared-db --command "SELECT * FROM token" > tokens-backup.json wrangler d1 execute npflared-db --command "SELECT * FROM package" > packages-backup.json
- R2 Data: Use R2 API or dashboard to backup tarballs
-
Clone this repository
-
Run the setup:
# Install dependencies pnpm install # Create infrastructure cd apps/api wrangler r2 bucket create coalesce-labs-npm-repository wrangler d1 create npflared-db # Update wrangler.production.toml with new database ID # Apply schema wrangler d1 execute npflared-db --file=migrations/0000_bright_mercury.sql # Deploy wrangler deploy --env production
-
Restore data from backups
wrangler tail --env productionVisit the Cloudflare Dashboard to view:
- Request analytics
- Error rates
- Performance metrics
βββ apps/
β βββ api/ # Main worker application
β βββ cli/ # CLI tools
β βββ doc/ # Documentation site
βββ infrastructure/
β βββ terraform/ # Terraform IaC files
β βββ scripts/ # Setup scripts
βββ .github/
β βββ workflows/ # GitHub Actions
βββ DEPLOYMENT.md # Detailed deployment guide
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
pnpm test - Submit a pull request
MIT License - see LICENSE file for details
- Check DEPLOYMENT.md for detailed deployment instructions
- View logs with
wrangler tail - Open an issue for bugs or feature requests
Current Deployment
- Production: https://npm.coalescelabs.ai
- Worker: npflared
- Region: Global (Cloudflare Edge)