Node.js PostgreSQL CRUD example: Rest APIs with Express & Sequelize

In this tutorial, I will show you step by step to build Node.js PostgreSQL CRUD Restful API example using Express and Sequelize.

Node.js PostgreSQL CRUD Rest API overview

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

First, we start with an Express web server. Next, we add configuration for PostgreSQL database, create model with Sequelize, write the controller. Then we define routes for handling all CRUD operations (including custom finder).

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

  • POST /api/tutorials: create new Tutorial
  • GET /api/tutorials: retrieve all Tutorials
  • GET /api/tutorials/[id]: retrieve a Tutorial by
  • PUT /api/tutorials/[id]: update a Tutorial by
  • DELETE /api/tutorials/[id]: delete a Tutorial by
  • DELETE /api/tutorials: delete all Tutorials
  • GET /api/tutorials/published: find all published Tutorials
  • GET/api/tutorials?title=[keyword]: find all Tutorials which title contains

Finally, we’re gonna test the Rest Apis using Postman.

This is our project structure:

Demo Video

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

Test the APIs

Run our Node.js application with command: .

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

  • Create a new Tutorial using Api
  • Retrieve all Tutorials using Api
  • Retrieve a single Tutorial by id using Api
  • Update a Tutorial using Api
  • Find all Tutorials which title contains ‘js’:
  • Find all published Tutorials using Api
  • Delete a Tutorial using Api
  • Delete all Tutorials using Api

For more details, implementation and Github, please visit:
https://bezkoder.com/node-express-sequelize-postgresql/

For more details, implementation and Github, please visit:
https://bezkoder.com/node-express-sequelize-postgresql/

For Server-side Pagination:
Node.js Express Pagination with PostgreSQL example

You can also find how to build a fullstack system with this app as backend server in the posts:
Vue.js + 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
React + Node.js Express + PostgreSQL example

Or Security: Node.js JWT Authentication & Authorization with PostgreSQL example

A passionate engineer in software development, especially web, mobile & cross-platform application. I love sharing knowledge by writing blogs & tutorials.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store