A RESTful Node.js API built with Express, MongoDB, and JWT authentication.
- 🚀 Modern ES Modules (ESM) syntax
- 🔐 JWT-based authentication
- 📦 MongoDB with Mongoose ODM
- ✅ Unit tests with Mocha, Chai, and Sinon
- 🔄 GitHub Actions CI/CD pipeline
- 📝 Request logging with Morgan
- Node.js >= 20.0.0
- MongoDB (local or remote)
# Clone the repository
git clone https://github.com/Rob-Leggett/node_restful_webservice.git
cd node_restful_webservice
# Install dependencies
npm installThe application uses environment variables for configuration:
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port |
MONGODB_URI |
mongodb://localhost:27017/node_restful_example |
MongoDB connection string |
JWT_SECRET |
examplesecret |
Secret key for JWT signing |
NODE_ENV |
- | Set to development to seed the database |
# Start with database seeding
npm run devnpm startThe server runs on http://localhost:3000 by default.
| Method | Endpoint | Description |
|---|---|---|
| POST | /authenticate |
Get JWT token |
Request body:
{
"name": "example",
"password": "password"
}All customer endpoints require a valid JWT token in the token header or Authorization: Bearer <token> header.
| Method | Endpoint | Description |
|---|---|---|
| GET | /customer |
Get all customers |
| GET | /customer/:id |
Get customer by ID |
| POST | /customer |
Create new customer |
| PUT | /customer/:id |
Update customer |
| DELETE | /customer/:id |
Delete customer |
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check endpoint |
npm test├── app/
│ ├── authenticate/ # Authentication module
│ ├── configuration/ # App configuration
│ ├── customer/ # Customer module
│ ├── user/ # User models and queries
│ ├── exceptionHandler.js
│ └── server.js
├── config/
│ └── seed.js # Database seeding
├── test/ # Unit tests
└── .github/workflows/ # CI/CD pipelines
This project is licensed under the MIT License - see the LICENSE file for details.
Robert Leggett
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request