Solution repo for the technical interview
- Create, read, update, delete users
- Each user can have their own collection of books
- The same book can't be added twice to the same user
- Node.js & Express
- TypeScript for better code quality
- MySQL database
-
Install packages
npm install
-
Build TypeScript
npm run build
-
Set up database
- Start MySQL server
- Create a database
- Run the SQL in
schema.sql
-
Set up environment (create
.envfile)DB_HOST=localhost DB_USER=root DB_PASSWORD=your_password DB_NAME=your_database_name (it takes 'library' as a default) PORT=3000
-
Start server
npm run dev
POST /users- Create userGET /users- Get all usersPUT /users/:id- Update userDELETE /users/:id- Delete user
POST /users/:userId/books- Add book to userGET /users/:userId/books- Get user's booksPUT /users/:userId/books/:bookId- Update user's bookDELETE /users/:userId/books/:bookId- Delete user's book
Create a user:
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'Add a book to user 1:
curl -X POST http://localhost:3000/users/1/books \
-H "Content-Type: application/json" \
-d '{"title":"1984","author":"George Orwell"}'- Server port: 3000
- MySQL port: 4000
- Database user: root
- No password
Change these in the .env file if needed.