This Example will show you how to make a REST API using Express.js and PostgreSQL.
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:
There is no big differences, between using MySQL or PostgreSQL database. So, I have added here only the code for Book Controller and Model. and Here are the most notable diffrences:
MySQL | PostgreSQL |
---|---|
response.json(dbResult); | response.json(dbResult.rows); |
insert into book_table (name, author, isbn) values(?,?,?) | insert into book_table (name, author, isbn) values($1,$2,$3); |