This Example will show you how to make a REST API using Express.js and MySQL.
The database of the example contains two tables: book and user. The user will be used to authorize the REST API users. So, in the exercise you will build a login system, so that the credentials will be checked based on the user.
The book -table has these fields:
It is important that the username is UNIQUE, so that two users can not have the same username. It would have been possible to make the username to be the primary key and remove the id_user. But nowadays using this kind of id's as the primary key is very popular way.
Also it is important that the length of the password is long (at least 64 bytes), because in the example the password will be encrypted using bcrypt and the hashed password will be very long. And if the field in the database is not enough long the application will not work.