A small Node.js REST API for managing YouTube-style subscriber records. It uses Express, MongoDB (via Mongoose), and automated tests, Docker, and CI/CD so you can run it locally, in a container, or deploy to Vercel after every push to main.
| Topic | What you practice |
|---|---|
| Node.js & Express | HTTP routes, JSON APIs, environment variables (MONGO_URI) |
| MongoDB | Schemas, seeding data, integration tests against a real database |
| Docker | Packaging the app with a Dockerfile for consistent runs |
| CI/CD | GitHub Actions: test on every PR/push, deploy to Vercel on main |
- Runtime: Node.js 20
- Framework: Express
- Database: MongoDB (Mongoose)
- Tests: Mocha, Chai, chai-http
- Deploy: Vercel (serverless Node via
vercel.json) - CI: GitHub Actions (
.github/workflows/ci.yml)
- Node.js 20.x
- MongoDB (local), or a cloud URI in
.env - For deployment: a Vercel project linked to this repo
- Clone the repository:
git clone https://github.com/Arpit-Works/Get-Youtube-Subscribers.git
cd Get-Youtube-Subscribers- Install dependencies:
npm install- Configure environment (create
.envin the project root):
MONGO_URI=mongodb://127.0.0.1:27017/subscribers
PORT=3000- Seed the database (MongoDB must be running):
node src/createDatabase.js- Start the server:
npm startThe API is available at http://localhost:3000.
- GET
/— Returns API status and available routes.
- GET
/subscribers— Array of subscriber documents.
- GET
/subscribers/names— Subscribers withnameandsubscribedChannelonly.
- GET
/subscribers/:id- Valid ID: single subscriber object.
- Invalid ID:
400with{ "message": "..." }.
npm testIn CI, tests run against a MongoDB service container on GitHub Actions: dependencies install with npm ci, the DB is seeded, then Mocha runs the suite.
The Dockerfile builds a minimal image: Node 20, npm ci, app code, and npm start on port 3000.
Build and run (set MONGO_URI to a host MongoDB or another container):
docker build -t get-youtube-subscribers .
docker run --rm -p 3000:3000 -e MONGO_URI=mongodb://host.docker.internal:27017/subscribers get-youtube-subscribers.dockerignore keeps node_modules, .env files, and git metadata out of the image.
Workflow file: .github/workflows/ci.yml.
-
Test job (every push and pull request to
main/master)- Spin up MongoDB
npm ci→ seed DB →npm test
-
Deploy job (only on push to
main, after tests pass)vercel pull— production env and project settingsvercel build --prod— build artifacts in.vercel/outputvercel deploy --prebuilt --prod— upload prebuilt output to Vercel
Add these under Repository → Settings → Secrets and variables → Actions:
| Secret | Description |
|---|---|
VERCEL_TOKEN |
Account token with access to your team (avoid project-only tokens for vercel pull) |
VERCEL_ORG_ID |
orgId from .vercel/project.json after vercel login and vercel link |
VERCEL_PROJECT_ID |
projectId from the same file (prj_…) |
Do not commit .vercel/ or .env files; they are listed in .gitignore.
vercel pullneeds the right token scope — Project-scoped tokens often fail with “Could not retrieve Project Settings”; use a full account/team token when using the officialpull→build→deploy --prebuiltflow.- IDs are not names —
VERCEL_ORG_IDisteam_…oruser_…, andVERCEL_PROJECT_IDisprj_…, not the project slug. - Link locally once — Run
vercel linkto generate.vercel/project.json, then copyorgIdandprojectIdinto GitHub secrets. - Separate test and deploy — PRs get tests only; production deploy runs only when
mainis green.
├── index.js # Vercel entry (routes to Express app)
├── vercel.json # Vercel serverless config
├── src/
│ ├── index.js # Local server entry
│ ├── app.js # Express routes and MongoDB connection
│ ├── createDatabase.js # Seed script
│ └── models/ # Mongoose models
├── __tests__/ # API tests
├── scripts/run-tests.js
├── Dockerfile
└── .github/workflows/ci.yml
ISC