A professional, lightweight Node.js API server built with TypeScript and native Node.js HTTP APIs. This project demonstrates custom routing, dynamic URL parameters, JSON request parsing, and file-based persistence in a clean, maintainable structure.
This repository is a real-world practice project for building a scalable Node.js backend without Express or external routing libraries.
It includes:
- Custom route registration using a centralized route map
- Dynamic route matching for parameterized paths such as
/api/users/:id - JSON body parsing with native Node.js streams
- File-based datastore using
src/data/user.json - Modular helpers for request handling and response serialization
- Environment-based configuration via
.env
src/
server.ts
config/
index.ts
data/
user.json
helpers/
RouterHandler.ts
dynamicRouterHandler.ts
fileDb.ts
parseBody.ts
sendJson.ts
routes/
index.ts
src/server.ts: starts the HTTP server, resolves requests, and dispatches handlers.src/helpers/RouterHandler.ts: stores routes per HTTP method and path.src/helpers/dynamicRouterHandler.ts: matches dynamic routes and extracts path parameters.src/helpers/parseBody.ts: parses incoming JSON request payloads.src/helpers/sendJson.ts: sends standardized JSON responses.src/helpers/fileDb.ts: reads and writes the user JSON datastore.src/routes/index.ts: defines API endpoints.
- Node.js 18 or newer
- npm
npm installCreate a .env file in the project root:
PORT=5000npx ts-node-dev --respawn --transpile-only src/server.tsYou should see:
server is running on port 5000Returns a welcome response.
Example:
curl http://localhost:5000/Response:
{
"message": "Hello from node js with typescript...",
"path": "/"
}Returns server health status.
Example:
curl http://localhost:5000/apiResponse:
{
"message": "Health status ok",
"path": "/api"
}Creates a new user in the JSON datastore.
Example:
curl -X POST http://localhost:5000/api/users \
-H "Content-Type: application/json" \
-d '{"id":3,"name":"New User"}'Response:
{
"success": true,
"data": {
"id": 3,
"name": "New User"
}
}Updates a user by ID.
Example:
curl -X PUT http://localhost:5000/api/users/1 \
-H "Content-Type: application/json" \
-d '{"name":"Updated Name"}'Response:
{
"success": true,
"message": "id 1 user updated",
"data": {
"id": 1,
"name": "Updated Name"
}
}- Uses TypeScript with strong typing and modern idioms
- Implements custom routing without Express
- Demonstrates a clean separation between configuration, routing, helpers, and data
- Easily extendable for additional REST endpoints and middleware
src/data/user.jsonis a simple prototype datastore. For production, replace it with a real database.- This repo is ideal for learning Node.js internals, TypeScript server design, and API structure.
- 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: nodejs-typescript-practice
- Maintainer: md-abu-kayser
- Email: abu.kayser.official@gmail.com
- GitHub: github.com/abu.kayser-official
If you’d like this README tailored for a specific purpose - such as hiring managers, open-source contributors, or client deliverables - feel free to request a custom tone or format.