This project is a simple Node.js API built with Express and TypeScript, based on the layered architecture. Below is an overview of the project structure, key features, and usage instructions.
.env
: Configuration file for environment variables..gitignore
: Specifies files and directories to be ignored by Git.package.json
: Contains project metadata and dependencies.tsconfig.json
: Configuration file for TypeScript.
Handles incoming HTTP requests and returns appropriate responses.
UserController.ts
: Manages user-related operations such as:- Fetching all users.
- Fetching a user by ID.
- Creating a new user.
Contains middleware functions for Express.
errorHandler.ts
: Generic middleware for handling errors.
Defines TypeScript interfaces and types.
User.ts
: Specifies theUser
interface.
Handles data interactions and operations.
UserRepository.ts
: Manages user data operations:- Fetching all users.
- Fetching a user by ID.
- Creating a new user.
Defines application route mappings.
userRoutes.ts
: Routes for user-related operations.
Contains business logic and service classes.
UserService.ts
: Provides services for:- Fetching all users.
- Fetching a user by ID.
- Creating a new user.
The entry point of the application. It:
- Sets up the Express server.
- Configures middleware.
- Defines routes.
- Integrates error handling.
Defined in the package.json
file for common tasks:
dev
: Runs the app in development mode withts-node-dev
for hot-reloading.build
: Compiles TypeScript to JavaScript.start
: Starts the compiled JavaScript application.
npm install
npm run dev
npm run build
npm start
This project provides a basic structure for building a RESTful API with Node.js, Express, and TypeScript, following the principles of layered architecture.