Sequelize CRUD MariaDB example | Build CRUD Node.js/Express RestAPIs example

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

Related posts:

Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL
Angular 6 HttpClient – Upload Files/Download Files to MySQL with Node.js/Express RestAPIs – using Multer + Sequelize ORM
Angular 6 HttpClient Crud + Node.js Express Sequelize + MySQL – Get/Post/Put/Delete RestAPIs
NodeJS – GridFS APIs Upload/Download Files to MongoDB – Mongoose
Angular 6 Client – Upload Files/Download Files to PostgreSQL with SpringBoot RestAPIs example
Sequelize One-To-One association – NodeJS/Express, MySQL


Related pages:

Overview

Project Design

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + architecture-project

Sequelize ORM
Installation

Setup Connection

Sequelize Model

Sequelize Create/Queries

– Create Object:

– Find All:

– Find By ID:

– Update a Customer:

– Delete a Customer:

Practice

Create a NodeJS/Express-Sequelize project as below structure ->

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + nodejs-project-structure

Setup NodeJs/Express Project

Following the guide to create a NodeJS/Express project.
Install Sequelize & MySQL:

-> package.json file:

Setup Sequelize MariaDB Connection

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

– Setup Sequelize-MariaDB connection in ./app/config/db.config.js file:

Sequelize Model

Express RestAPIs
Route

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

Controller

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

Server.js

Run & Check Results

Start Node.js server ->

– POST customers ->

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + post-request

– GET all customers ->

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + get-all-request

– GET a customer by ID:

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + get-a-customer-by-id-request

– PUT a customer ->

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + put-a-customer-by-id

– DELETE a customer by ID ->

nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + destroy-request

Sequelize’s Logs ->

SourceCode

How to work with the below sourcecode?

– Download the sourcecode -> We get a file Nodejs-Express-Sequelizejs-MariaDB.zip.
– Extract the zip file, then cd to folder Nodejs-Express-Sequelizejs-MariaDB.
– Install libs by commandline: npm install
– Start MariaDB
– Start Node.js server by cmd: npm start

Sourcecode ->

Nodejs-Express-Sequelizejs-MariaDB

By grokonez | August 18, 2018.



Related Posts


1 thought on “Sequelize CRUD MariaDB example | Build CRUD Node.js/Express RestAPIs example”

Got Something To Say:

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

*