A complete, ready-to-run CRUD API server built with Node.js, Express, and Sequelize ORM, featuring a React frontend for full-stack functionality.
This project demonstrates a full-stack application with:
- Backend: RESTful API with complete CRUD operations
- Frontend: React-based user interface with Tailwind CSS
- Database: PostgreSQL with Sequelize ORM
- Testing: Comprehensive test suite with Jest and Supertest
- Documentation: Complete API documentation
- Node.js (LTS) - JavaScript runtime
- Express.js - Web application framework
- Sequelize - Promise-based ORM for SQL databases
- PostgreSQL - PostgreSQL database
- Jest + Supertest - Testing framework
- React - User interface library
- Axios - HTTP client for API calls
- Tailwind CSS - Utility-first CSS framework
Before running this project, ensure you have:
- Node.js (v16 or higher)
- npm or yarn package manager
git clone <repository-url>
cd crud-api-servercd backend
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
# Run database migrations
npm run migrate
# Start the development server
npm run devcd frontend
# Install dependencies
yarn install
# Start the development server
yarn startBackend Health Check:
curl http://localhost:8001/healthAccess Frontend:
Open your browser and navigate to http://localhost:3000
cd backend
npm testThe test suite includes:
- ✅ All CRUD operations (Create, Read, Update, Delete)
- ✅ Input validation and error handling
- ✅ Success and error scenarios
- ✅ Database operations and constraints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Server health check |
| GET | /api/items |
Retrieve all items |
| GET | /api/items/:id |
Retrieve specific item |
| POST | /api/items |
Create new item |
| PUT | /api/items/:id |
Update existing item |
| DELETE | /api/items/:id |
Delete item |
For detailed API documentation, see API_DOCS.md.
├── backend/ # Express.js backend
│ ├── src/
│ │ ├── config/ # Database configuration
│ │ ├── models/ # Sequelize models
│ │ ├── routes/ # API routes
│ │ ├── controllers/ # Route controllers
│ │ └── app.js # Express application
│ ├── tests/ # Test files
│ ├── server.js # Server entry point
│ └── package.json # Dependencies and scripts
├── frontend/ # React frontend
│ ├── src/
│ │ ├── App.js # Main React component
│ │ └── App.css # Styling
│ └── package.json # Dependencies and scripts
├── API_DOCS.md # API documentation
└── README.md # This file
- Prepare for Heroku:
# Add Heroku Postgres addon
heroku addons:create heroku-postgresql:mini
# Set production environment variables
heroku config:set NODE_ENV=production
heroku config:set DB_DIALECT=postgres- Update package.json:
{
"scripts": {
"postbuild": "npm run migrate",
"start": "node server.js"
}
}- Deploy:
git add .
git commit -m "Ready for deployment"
git push heroku main- Create Dockerfile:
FROM node:18-alpine
WORKDIR /app
# Backend setup
COPY backend/package*.json ./backend/
RUN cd backend && npm install
# Frontend setup
COPY frontend/package*.json ./frontend/
RUN cd frontend && npm install
COPY . .
# Build frontend
RUN cd frontend && npm run build
# Run migrations and start server
EXPOSE 8001
CMD cd backend && npm run migrate && npm start- Build and run:
docker build -t crud-api-server .
docker run -p 8001:8001 crud-api-servernpm start # Start production server
npm run dev # Start development server with hot reload
npm test # Run test suite
npm run migrate # Run database migrationsyarn start # Start development server
yarn build # Build for production
yarn test # Run React tests- ✅ Complete CRUD operations
- ✅ Input validation with express-validator
- ✅ Comprehensive error handling
- ✅ Database migrations and models
- ✅ CORS support for cross-origin requests
- ✅ Security headers with Helmet
- ✅ Structured JSON responses
- ✅ Extensive test coverage
- ✅ Modern React with Hooks
- ✅ Responsive design with Tailwind CSS
- ✅ Real-time CRUD operations
- ✅ Form validation and error handling
- ✅ Loading states and user feedback
- ✅ Confirmation dialogs for destructive actions
- ✅ Auto-refresh and manual refresh options
- 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
If you encounter any issues or have questions:
- Check the API Documentation
- Review the test files for usage examples
- Open an issue on GitHub
Built using Node.js, Express, React, and Sequelize