A modern Vanilla Node.js REST API with CLI, Interactive UI Tester, and comprehensive testing suite.
- π CLI Tool - Laravel/AdonisJS-style commands for routes and scaffolding
- π UI API Tester - Interactive web interface for testing endpoints
- π§ͺ Testing Framework - Custom test runner on pure Node.js (31 tests)
- π¦ Service Architecture - Clean separation of business logic and HTTP handlers
- π Prisma ORM - Type-safe database access with PostgreSQL
- β‘ Graceful Shutdown - Proper signal handling and cleanup
- Node.js v24.14.0 or higher
- PostgreSQL database (or use Prisma Accelerate)
# Clone the repository
git clone <your-repo-url>
cd node-api
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your DATABASE_URL
# Generate Prisma Client
npx prisma generate
# Run migrations
npx prisma migrate dev
# Start development server
npm run devNavigate to http://localhost:3000 in your browser.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
UI API Tester |
| GET | /faker |
Generate fake user data |
| Method | Endpoint | Description |
|---|---|---|
| GET | /posts |
Get all posts |
| GET | /posts/:id |
Get post by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all users |
| GET | /users/:id |
Get user by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | /categories |
Get all categories |
| GET | /categories/:id |
Get category by ID |
| POST | /categories |
Create category |
| PUT | /categories/:id |
Update category |
| DELETE | /categories/:id |
Delete category |
| Method | Endpoint | Description |
|---|---|---|
| GET | /notes |
Get all notes |
| GET | /notes/:id |
Get note by ID |
| POST | /notes |
Create note |
| PUT | /notes/:id |
Update note |
| DELETE | /notes/:id |
Delete note |
node src/cli.js routesOutput:
βΌ API Routes
βββββββββΌββββββββββββββββΌββββββββββββββββββββββ
β Method β Path β Handler β
βββββββββΌββββββββββββββββΌββββββββββββββββββββββ€
β GET β /categories β categoriesController β
β POST β /categories β categoriesController β
β PUT β /categories/:id β categoriesController β
β DELETE β /categories/:id β categoriesController β
βββββββββΌββββββββββββββββΌββββββββββββββββββββββ
node src/cli.js scaffold <EntityName>
# Examples
node src/cli.js scaffold Product
node src/cli.js scaffold Order
node src/cli.js scaffold CustomerThis creates:
src/services/<entity>.js- Service layer with CRUD methodssrc/controllers/<entity>.js- HTTP request handlers- Auto-registers 5 routes in
src/routes.js
node src/cli.js helpnpm testβ Passed: 31
β Failed: 0
Total: 31
Tests are located in tests/unit/ and use a custom test runner built on pure Node.js (node:assert, node:events).
import { describe, it, assert, beforeEach } from '../runner.js';
import { mockPrisma } from '../mocks/prisma.js';
describe('CategoriesController', () => {
beforeEach(() => {
mockPrisma.$reset();
});
it('should return all categories', async () => {
const controller = createController();
const result = await controller.getAll();
assert(Array.isArray(JSON.parse(result)));
});
});model Category {
id Int @id @default(autoincrement())
name String
notes Note[]
}model Note {
id Int @id @default(autoincrement())
title String
content String?
archived Boolean @default(false)
categoryId Int
category Category @relation(fields: [categoryId], references: [id])
}node-api/
βββ src/
β βββ server.js # HTTP server + static files
β βββ config.js # Environment configuration
β βββ cli.js # CLI tool
β βββ routes.js # Route definitions
β βββ loger.js # Logging middleware
β βββ controllers/ # HTTP handlers
β β βββ categories.js
β β βββ notes.js
β β βββ index.js
β βββ services/ # Business logic
β βββ category.js
β βββ note.js
βββ tests/
β βββ runner.js # Test runner
β βββ mocks/
β β βββ prisma.js # Mock Prisma client
β βββ unit/
β βββ categories.test.js
β βββ notes.test.js
βββ public/
β βββ index.html # UI API Tester
βββ prisma/
β βββ schema.prisma
β βββ migrations/
β βββ seeds.js
βββ .env.example
βββ package.json
βββ README.md
Create a .env file in the root directory:
# Database (Prisma Accelerate or local PostgreSQL)
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=YOUR_KEY"
# Or: DATABASE_URL="postgresql://user:password@localhost:5432/nodeapi"
# Server
PORT=3000
NODE_ENV=developmentnpm start # Start production server
npm run dev # Start development server with --watch
npm test # Run unit tests
npm run seeds # Seed database with test data
node src/cli.js routes # Show all routes
node src/cli.js scaffold Product # Generate CRUD
node src/cli.js help # Show CLI help- Open http://localhost:3000
- Select an endpoint from the left panel
- Configure request (ID, JSON body)
- Click "Send Request"
- View formatted response
# Get all categories
curl http://localhost:3000/categories
# Get category by ID
curl http://localhost:3000/categories/1
# Create category
curl -X POST http://localhost:3000/categories \
-H "Content-Type: application/json" \
-d '{"name": "New Category"}'
# Update category
curl -X PUT http://localhost:3000/categories/1 \
-H "Content-Type: application/json" \
-d '{"name": "Updated Category"}'
# Delete category
curl -X DELETE http://localhost:3000/categories/1# Get all notes
Invoke-RestMethod -Uri 'http://localhost:3000/notes'
# Create note
$body = @{title='New Note'; categoryId=1} | ConvertTo-Json
Invoke-RestMethod -Uri 'http://localhost:3000/notes' `
-Method Post -Body $body -ContentType 'application/json'HTTP Request
β
server.js (Static files β API routing)
β
routes.js (Route matching)
β
controller (HTTP handling, validation)
β
service (Business logic, Prisma)
β
Prisma β Database
β
Response (JSON)
- ES Modules - Modern JavaScript module system
- Service Layer - Isolated business logic for easy testing
- Controller Layer - HTTP-specific handling and validation
- Mock Prisma - In-memory database for unit tests
- Graceful Shutdown - Proper cleanup on SIGTERM/SIGINT
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
- CLI design inspired by Laravel Artisan and AdonisJS Ace
- UI Tester design inspired by modern API testing tools
- Testing framework built on Node.js built-in modules
Built with β€οΈ using Node.js, Prisma, and PostgreSQL