A simple REST API built with Node.js, Express, and PostgreSQL (via Prisma ORM). This project is designed for practicing DevOps, SRE, and cloud infrastructure skills. It includes user and message management, health checks, and a basic web UI.
- RESTful API for users and messages
- PostgreSQL database with Prisma ORM
- Express.js server with logging (Pino)
- Health check endpoint
- Static web dashboard (HTML/JS)
- Graceful shutdown and error handling
- Docker and Docker Compose support
- Environment variable configuration
- Ready for cloud deployment
GET /health— Health checkGET /users— List usersPOST /users— Create userGET /users/:id— Get user by IDDELETE /users/:id— Delete userGET /messages— List messagesPOST /messages— Create messageGET /messages/:id— Get message by IDDELETE /messages/:id— Delete message
- Node.js (v18+ recommended)
- PostgreSQL database
- npm
- Clone the repository:
git clone <repo-url> cd nodejs-simpleapi-with-db
- Install dependencies:
npm install
- Configure environment variables:
- Copy
.envand updateDATABASE_URLfor your PostgreSQL instance.
- Copy
- Run database migrations:
npm run db:migrate
- (Optional) Seed the database:
npm run db:seed
- Start the development server:
The app will be available at http://localhost:3000
npm run dev
npm testnpm run build
npm startBuild and run the app in Docker:
docker build -t simpleapi .
docker run --env-file .env -p 3000:3000 simpleapiOr use Docker Compose (add your service config to docker-compose.yml):
docker-compose up --build├── src/
│ ├── index.ts # Entry point
│ ├── server.ts # Express app and server logic
│ ├── lib/
│ │ ├── prisma.ts # Prisma client
│ │ └── logger.ts # Centralized logger
│ ├── routes/ # API route handlers
│ └── public/ # Static HTML dashboard
├── prisma/ # Prisma schema and migrations
├── tests/ # Integration and helper tests
├── Dockerfile # Docker build config
├── .env # Environment variables
├── package.json # NPM scripts and dependencies
└── README.md # Project documentation
- Uses Pino for structured logging.
- Logs requests, errors, and important events.
MIT