Angular 6 HttpClient – PostgreSQL – Node.js/Express Sequelize CRUD APIs
Tags: angular, httpclient, node, express
Published: 2021-05-13 05:22:20

Angular 6 HttpClient – PostgreSQL – Node.js/Express Sequelize CRUD APIs – Post/Get/Put/Delete

https://grokonez.com/frontend/angular/angular-6/angular-6-httpclient-postgresql-node-js-express-sequelize-crud-apis-post-get-put-delete

Sequelize is a promise-based ORM for Node.js v4 and later. In the tutorial, we will show how to <code>GET/POST/PUT/DELETE</code> requests from Angular 6 Client to PostgreSQL with NodeJs/Express RestAPIs using Sequelize ORM.

Related posts:
- <a href="https://grokonez.com/node-js/sequelize/node-js-express-restapis-get-post-put-delete-sequelize-crud-postgresql">Node.js/Express RestAPIs CRUD – Sequelize ORM – PostgreSQL</a>
- <a href="https://grokonez.com/frontend/angular/angular-6/nodejs-restapis-angular-6-httpclient-get-post-put-delete-requests-bootstrap-4">Node.js/Express RestAPIs – Angular 6 HttpClient – Get/Post/Put/Delete requests + Bootstrap 4</a>

<!--more-->
<h2>Technologies</h2>
<ul>
<li>Angular 6</li>
<li>RxJS 6</li>
<li>Bootstrap 4</li>
<li>Visual Studio Code – version 1.24.0</li>
<li>Nodejs – v8.11.3</li>
<li>Sequelize</li>
<li>PostgreSQL</li>
</ul>
<h2>Demo</h2>
<iframe width="853" height="480" src="https://www.youtube.com/embed/TU0t7nQYa5U?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<h2>Overview</h2>
<h3>Goal</h3>
We create 2 projects:

– Angular Client Project:

<img src="https://grokonez.com/wp-content/uploads/2018/07/angular-6-http-client-nodejs-express-sequelize-crud-postgresql-angular-project-structure.png" alt="angular-6-http-client-nodejs-express-sequelize-crud-postgresql + angular-project-structure" width="212" height="485" class="alignnone size-full wp-image-13604" />

– Node.js RestAPIs project:

<img src="https://grokonez.com/wp-content/uploads/2018/07/angular-6-http-client-nodejs-express-sequelize-crud-postgresql-nodejs-project-structure.png" alt="angular-6-http-client-nodejs-express-sequelize-crud-postgresql + nodejs-project-structure" width="261" height="328" class="alignnone size-full wp-image-13605" />

<strong>UserCase</strong>

Start Node.js server -> Logs:

<pre><code class="language-javascript">
App listening at http://:::8080
Executing (default): DROP TABLE IF EXISTS "customers" CASCADE;
Executing (default): DROP TABLE IF EXISTS "customers" CASCADE;
Executing (default): CREATE TABLE IF NOT EXISTS "customers" ("id"   SERIAL , "firstname" VARCHAR(255), "lastname" VARCHAR(255), "age" INTEGER, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
Executing (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'customers' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;
Drop and Resync with { force: true }
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'Joe','Thomas',36,'2018-07-11 08:31:06.976 +00:00','2018-07-11 08:31:06.976 +00:00') RETURNING *;
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'Peter','Smith',18,'2018-07-11 08:31:06.977 +00:00','2018-07-11 08:31:06.977 +00:00') RETURNING *;
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'Lauren','Taylor',31,'2018-07-11 08:31:06.978 +00:00','2018-07-11 08:31:06.978 +00:00') RETURNING *;
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'Mary','Taylor',24,'2018-07-11 08:31:06.978 +00:00','2018-07-11 08:31:06.978 +00:00') RETURNING *;
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'David','Moore',25,'2018-07-11 08:31:06.978 +00:00','2018-07-11 08:31:06.978 +00:00') RETURNING *;
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'Holly','Davies',27,'2018-07-11 08:31:06.978 +00:00','2018-07-11 08:31:06.978 +00:00') RETURNING *;
Executing (default): INSERT INTO "customers" ("id","firstname","lastname","age","createdAt","updatedAt") VALUES (DEFAULT,'Michael','Brown',45,'2018-07-11 08:31:06.979 +00:00','2018-07-11 08:31:06.979 +00:00') RETURNING *;
</code></pre>

-> PostgreSQL records:

More at:
Angular 6 HttpClient – PostgreSQL – Node.js/Express Sequelize CRUD APIs – Post/Get/Put/Delete

https://grokonez.com/frontend/angular/angular-6/angular-6-httpclient-postgresql-node-js-express-sequelize-crud-apis-post-get-put-delete