A professional, production-ready CRUD (Create, Read, Update, Delete) API built entirely with raw Node.js and TypeScript. This project demonstrates advanced server-side development techniques without relying on frameworks like Express, showcasing deep understanding of HTTP protocols, routing, and asynchronous programming.
- Framework-Free: Built with raw Node.js HTTP module for maximum control and minimal dependencies
- TypeScript Integration: Full type safety with custom interfaces and type definitions
- Custom Router: High-performance routing system supporting static and dynamic routes
- Environment Configuration: Secure environment-based configuration using dotenv
- JSON Database: Lightweight file-based database with atomic write operations
- Comprehensive CRUD Operations: Complete user management API with validation
- Error Handling: Robust error handling with proper HTTP status codes
- Async/Await Support: Modern asynchronous programming patterns
- Input Validation: Built-in validation for API inputs
- Modular Architecture: Clean, maintainable code structure
- Runtime: Node.js 18+
- Language: TypeScript 5.0+
- HTTP Handling: Node.js built-in
httpmodule - Configuration: dotenv
- Development: ts-node-dev, nodemon-like hot reloading
- Testing: Manual testing with curl/Postman
- Database: JSON file (easily replaceable with real databases)
-
Clone the repository
git clone https://github.com/md-abu-kayser/raw-node-typescript-crud-api.git cd raw-node-typescript-crud-api -
Install dependencies
npm install
-
Environment Setup (Optional) Create a
.envfile in the root directory:PORT=5000 NODE_ENV=development
-
Start the development server
npm run dev
The server will start on http://localhost:5000 (or your configured PORT).
npm run dev # Start development server with hot reload
npm run build # Compile TypeScript to JavaScript
npm run start # Run production server
npm run typecheck # Run TypeScript type checkingUse curl, Postman, or any HTTP client to test the endpoints.
curl http://localhost:5000/healthcurl http://localhost:5000/api/userscurl -X POST http://localhost:5000/api/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"country": "United States",
"study": "Computer Science"
}'curl http://localhost:5000/api/users/1curl -X PUT http://localhost:5000/api/users/1 \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Doe",
"country": "Canada"
}'curl -X DELETE http://localhost:5000/api/users/1| Method | Endpoint | Description | Request Body |
|---|---|---|---|
| GET | / |
Welcome message | - |
| GET | /health |
Server health check | - |
| GET | /api/users |
Get all users | - |
| GET | /api/users/:id |
Get user by ID | - |
| POST | /api/users |
Create new user | {name, country, study} |
| PUT | /api/users/:id |
Update user by ID | {name?, country?, study?} |
| DELETE | /api/users/:id |
Delete user by ID | - |
{
"success": true,
"message": "User created successfully",
"data": {
"id": 1,
"name": "John Doe",
"country": "United States",
"study": "Computer Science",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
}{
"success": false,
"message": "User not found"
}raw-node-typescript-crud-api/
βββ src/
β βββ server.ts # Main server file
β βββ config/
β β βββ index.ts # Environment configuration
β βββ data/
β β βββ users.json # JSON database file
β βββ helpers/
β β βββ router.ts # Custom routing system
β β βββ sendJson.ts # JSON response helper
β β βββ parseBody.ts # Request body parser
β β βββ fileDb.ts # File database operations
β β βββ validators.ts # Input validation utilities
β βββ routes/
β β βββ index.ts # API route definitions
β βββ types/
β βββ http.ts # HTTP type definitions
β βββ user.ts # User data types
βββ package.json
βββ tsconfig.json
βββ .env # Environment variables (create if needed)
βββ README.md
- High Performance: O(1) route lookups using Map data structures
- Dynamic Routes: Support for parameterized routes (e.g.,
/users/:id) - Method-Based Routing: Separate route maps for each HTTP method
- Atomic Operations: Uses temporary files to prevent data corruption
- Error Recovery: Graceful handling of file read/write errors
- Easy Migration: Simple to replace with SQL/NoSQL databases
- Type Safety: Comprehensive interfaces for all data structures
- IntelliSense: Full IDE support with autocompletion
- Compile-Time Checks: Catch errors before runtime
We welcome contributions! Please follow these steps:
- 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
- Follow TypeScript best practices
- Add tests for new features
- Update documentation
- Use conventional commit messages
- This project is licensed under the terms of the MIT License.
- You may replace or update the license as needed for client or proprietary projects.
- Name: Md Abu Kayser
- Project: raw-node-typescript-crud-api
- Maintainer: md-abu-kayser
- Email: abu.kayser.official@gmail.com
- GitHub: github.com/abu.kayser-official
- Node.js community for the amazing runtime
- TypeScript team for the powerful type system
- Open source contributors who make projects like this possible
β Star this repo if you found it helpful!
For questions or support, please open an issue on GitHub.