This is a RESTful API project built with TypeScript, Node.js, and Express.
This project implements user-related APIs, including CRUD operations. The structure is clear and suitable for learning and practicing TypeScript backend development.
jest.config.js
nodemon.json
package.json
tsconfig.json
src/
index.ts
server.ts
controllers/
users.controller.ts
routes/
index.ts
users.route.ts
services/
users.service.ts
types/
api-response.ts
user.ts
test/
controllers/
users.test.ts
services/
users.service.test.ts
-
Clone the repository:
git clone https://github.com/coderjingtao/TypeScript-Tutorial.git cd TypeScript-Tutorial
-
Install dependencies:
npm install
-
(Optional) Copy and edit environment variables:
cp .env.example .env # Edit .env as needed
-
Start the server:
npm run dev
The default port is
3000
. -
Main user-related endpoints:
- Get all users:
GET /api/users
- Get a specific user:
GET /api/users/:id
- Create a user:
POST /api/users Content-Type: application/json { "name": "username", "email": "email" }
- Update a user:
PUT /api/users/:id Content-Type: application/json { "name": "new username", "email": "new email" }
- Delete a user:
DELETE /api/users/:id
- Get all users:
-
You can use Postman, curl, or any other HTTP client to test the endpoints.
- Run tests:
npm run test
This will automatically run all unit tests in the test/
directory.
- Testing framework:
- Jest is used for unit testing.
- Test files are located in
test/controllers/
andtest/services/
.
- Test coverage:
- Main features of user services and controllers.
If you have any questions or suggestions, feel free to open an issue or submit a PR.