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

16 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,


    However, with this Api, will a user be authenticated with a token before they can Post or Create something on the website ?

    For instance, if you have a website where user are authenticated before doing something, will this api apply or they are separately done? I wish we could talk more.

  3. Thank you so so much! You have helped me a lot.
    One question sir, how can I associate multiple models with this kind of setup?
    I’ve only seen examples of models being associated when they are on the same file.
    Please help me, sir. I’m totally lost.

  4. could you explain me this part i didn’t get it from database config file

  5. Hi, Great Job
    When doing a post for http://localhost:8081/api/customers
    the firstname, lastname and age is not inserting into the database please can anyone help

    Executing (default): INSERT INTO customers (id,createdAt,updatedAt) VALUES (DEFAULT,’2019-03-25 01:43:05′,’2019-03-25 01:43:05′);

    Please any help?


Got Something To Say:

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