Git Product home page Git Product logo

node-js-postgresql-crud-example's Introduction

Node.js PostgreSQL CRUD example with Express Rest APIs

Full Article with implementation:

Node.js PostgreSQL CRUD example with Express Rest APIs

We will build Rest Apis that can create, retrieve, update, delete and find Tutorials by title.

The following table shows overview of the Rest APIs that will be exported:

  • GET api/tutorials get all Tutorials
  • GET api/tutorials/:id get Tutorial by id
  • POST api/tutorials add new Tutorial
  • PUT api/tutorials/:id update Tutorial by id
  • DELETE api/tutorials/:id remove Tutorial by id
  • DELETE api/tutorials remove all Tutorials
  • GET api/tutorials/published find all published Tutorials
  • GET api/tutorials?title=[kw] find all Tutorials which title contains 'kw'

Demo Video

This is our Node.js PostgreSQL CRUD example using Express & Sequelize application demo, test Rest Apis with Postman.

Node.js PostgreSQL CRUD example Github

Test the APIs

Run our Node.js application with command: node server.js.

Using Postman, we're gonna test all the Apis above.

  • Create a new Tutorial using POST /tutorials Api

node-js-postgresql-crud-example-create

After creating some new Tutorials, you can check PostgreSQL table:

 id |    title    |    description    | published |         createdAt          |         updatedAt
----+-------------+-------------------+-----------+----------------------------+----------------------------
  1 | Node Tut #1 | Tut#1 Description | f         | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07
  2 | Node Tut #2 | Tut#2 Description | f         | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:43:05.131+07
  3 | Node Tut #3 | Tut#3 Description | f         | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07
  4 | Js Tut #4   | Tut#4 Desc        | f         | 2020-01-29 10:45:40.016+07 | 2020-01-29 10:45:40.016+07
  5 | Js Tut #5   | Tut#5 Desc        | f         | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:45:44.289+07
  • Retrieve all Tutorials using GET /tutorials Api

node-js-postgresql-crud-example-retrieve-all

  • Retrieve a single Tutorial by id using GET /tutorials/:id Api

node-js-postgresql-crud-example-retrieve-one

  • Update a Tutorial using PUT /tutorials/:id Api

node-js-postgresql-crud-example-update

Check tutorials table after some rows were updated:

 id |     title      |    description    | published |         createdAt          |         updatedAt
----+----------------+-------------------+-----------+----------------------------+----------------------------
  1 | Node Tut #1    | Tut#1 Description | f         | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07
  3 | Node Tut #3    | Tut#3 Description | f         | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07
  2 | Node Js Tut #2 | Tut#2 Description | t         | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:51:55.235+07
  4 | Js Tut #4      | Tut#4 Desc        | t         | 2020-01-29 10:45:40.016+07 | 2020-01-29 10:54:17.468+07
  5 | Js Tut #5      | Tut#5 Desc        | t         | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:54:20.544+07
  • Find all Tutorials which title contains 'js': GET /tutorials?title=js

node-js-postgresql-crud-example-search

  • Find all published Tutorials using GET /tutorials/published Api

node-js-postgresql-crud-example-search-status

  • Delete a Tutorial using DELETE /tutorials/:id Api

node-js-postgresql-crud-example-delete-one

Tutorial with id=4 was removed from tutorials table:

 id |     title      |    description    | published |         createdAt          |         updatedAt
----+----------------+-------------------+-----------+----------------------------+----------------------------
  1 | Node Tut #1    | Tut#1 Description | f         | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07
  3 | Node Tut #3    | Tut#3 Description | f         | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07
  2 | Node Js Tut #2 | Tut#2 Description | t         | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:51:55.235+07
  5 | Js Tut #5      | Tut#5 Desc        | t         | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:54:20.544+07
  • Delete all Tutorials using DELETE /tutorials Api

node-js-postgresql-crud-example-delete-all

Now there are no rows in tutorials table:

 id | title | description | published | createdAt | updatedAt
----+-------+-------------+-----------+-----------+-----------

For more detail, please visit:

Node.js PostgreSQL CRUD example with Express Rest APIs

Node.js Express Pagination with PostgreSQL example

Security:

Node.js JWT Authentication & Authorization with PostgreSQL example

Associations:

Sequelize Associations: One-to-Many Relationship example

Sequelize Associations: Many-to-Many Relationship example

Fullstack:

Vue + Node.js + Express + PostgreSQL example

React + Node.js + Express + PostgreSQL example

ANgular 8 + Node.js + Express + PostgreSQL example

ANgular 10 + Node.js + Express + PostgreSQL example

ANgular 11 + Node.js + Express + PostgreSQL example

Project setup

npm install

Run

node server.js

node-js-postgresql-crud-example's People

Contributors

tienbku avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.