Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL


Sequelize is a promise-based ORM for Node.js v4 and later. In the tutorial, we will show how to build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL.

– Related posts:
Sequelize One-To-One association – NodeJS/Express, MySQL

Sequelize ORM

Sequelize is a promise-based Node.js ORM for Postgres, MySQL, SQLite and Microsoft SQL Server. It has many solid features for transaction, relations, read replication and more.

Getting started with MySQL:


Set up a connection

Sequelize model

Sequelize queries

– Find all:

– Find By ID:

– Update a Customer:

– Delete a Customer:


We create a NodeJS/Express-Sequelize project as below structure:

Setting up NodeJs/Express project

Following the guide to create a NodeJS/Express project.

Install Sequelize with MySQL:

-> package.json file:

Setting up Sequelize MySQL connection

– Create ‘./app/config/env.js’ file:

– Setup Sequelize-MySQL connection in ‘./app/config/db.config.js’ file:

Create Sequelize model

Express RestAPIs

Define Customer’s routes in ‘./app/controller/customer.route.js’ file:


Implement Customer’s controller in ‘./app/controller/customer.controller.js’ file:


Run & Check results

Start NodeJs server:

Use Postman to check result ->

– POST customers:



– GET all customers:


– GET a customer by id:


– PUT a customer:


– DELETE a customer by Id:


Log from Server:

– Check customer table:




By grokonez | April 18, 2018.

Last updated on September 28, 2018.

Related Posts

7 thoughts on “Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL”

  1. Great article. I do not understand the part of the routes because in Express we usually import the Route () and use it like this:

    I also found the structure of server.js a bit different from an Express application, but it works very well.
    Would this be a more modern form of construction?

    1. Hello Julio,

      Please take a look at the overall design structure of Node.js project,

      -> With about organized structure, we create an easy way to develop big Node.js projects, more easy way to extends functions with seperated controller & router files. It also a design to reduce many codes for server.js.

      With mini project, you can develop restAPIs right in server.js -> BUT not good for real development.

      Here is an option for your development.

      Thanks & Regards,

Got Something To Say:

Your email address will not be published. Required fields are marked *