![logo](../jsxcode/images/jsxcode.png)
- Software Engineer, Product
- Modern Technology stacks:
- So What is a Tech Stack?
- Frontend tech stack
- Backend tech stack
- How to choose/build a tech stack
- What is a CI/CD Pipeline?
- Software Business Analyst
- Node.js Express Back-end Overview
- Build React App With Java Backend
- Connecting React-Frontend and NodeJS/Express Backend Applications
- React-Frontend, Node.js/Express-Backend, MySQL Architecture
- React Frontend with a NodeJS/Express Backend
- So What is git ?
- Git vs GitHub
- Big O Notation
![logo](../jsxcode/images/hj-codes.png)
![logo](http://jsxcode.com/jsxcode/images/A-wareaddy.png)
SQL Server Architecture
React-Frontend, Node.js and Express-Backend
We're gonna build the application with following architecture:
Fronend:
React Client sends HTTP Requests and retrieves HTTP Responses using Axios,consume data on the components.
React Router is used for navigating to pages.
Backend:
Node.js Express exports REST APIs & interacts with SQL Database using Sequelize Object-relational mapping (ORM)
Finally, we're gonna test the Rest Apis using Postman.
This is our project structure:
We need to install necessary modules: express, sequelize, tedious
Run the command:
The package.json file should look like this:
Yeah, the first step is done. We're gonna work with Sequelize in the next section.
First five parameters are for SQL Server / MSSQL connection.
pool is optional, it will be used for Sequelize connection pool configuration:
max: maximum number of connection in pool
min: minimum number of connection in pool
idle: maximum time, in milliseconds, that a connection can be idle before being released
acquire: maximum time, in milliseconds, that pool will try to get connection before throwing error
In development, you may need to drop existing tables and re-sync database. Just use force: true as following code:
We can easily modify db.config.js to change anytime with SQL Server.
Create the Controller
Inside app/controllers folder, let's create tutorial.controller.js with these CRUD functions:
create
findAll
findOne
update
delete
deleteAll
findAllPublished
Let's implement these functions.
We use req.query.title to get query string from the Request and consider it as condition for findAll() method.
This controller can be modified a little to return pagination response:
SQL Automation Tools..... Contributed by Jama Hassan
My current Solutions Architect position has afforded me the opportunity to organize and develop the entire solutions process from start to finish.
![](http://jsxcode.com/images/SQL-server-architecture.png)
React Client sends HTTP Requests and retrieves HTTP Responses using Axios,consume data on the components.
React Router is used for navigating to pages.
Backend:
Node.js Express exports REST APIs & interacts with SQL Database using Sequelize Object-relational mapping (ORM)
![](http://jsxcode.com/images/overview.png)
Finally, we're gonna test the Rest Apis using Postman.
This is our project structure:
![](http://jsxcode.com/imagesold/node-js-crud-sql-server-mssql-project-structure.png)
![](http://jsxcode.com/imagesold/create-npde-js-mssql-app.png)
We need to install necessary modules: express, sequelize, tedious
Run the command:
npm install express sequelize tedious cors
The package.json file should look like this:
![](http://jsxcode.com/imagesold/package-json.png)
![](http://jsxcode.com/imagesold/Connect-SQL.png)
![](http://jsxcode.com/imagesold/Connect-SQL2.png)
![](http://jsxcode.com/imagesold/Connect-SQL-localhost.png)
Yeah, the first step is done. We're gonna work with Sequelize in the next section.
![](http://jsxcode.com/imagesold/confg-mssql-db-sequilize.png)
First five parameters are for SQL Server / MSSQL connection.
pool is optional, it will be used for Sequelize connection pool configuration:
max: maximum number of connection in pool
min: minimum number of connection in pool
idle: maximum time, in milliseconds, that a connection can be idle before being released
acquire: maximum time, in milliseconds, that pool will try to get connection before throwing error
![](http://jsxcode.com/imagesold/intailize-sequenlize.png)
![](http://jsxcode.com/imagesold/intailize-sequenlize2.png)
In development, you may need to drop existing tables and re-sync database. Just use force: true as following code:
![](http://jsxcode.com/imagesold/intailize-sequenlize3.png)
![](http://jsxcode.com/imagesold/intailize-sequenlize4.png)
We can easily modify db.config.js to change anytime with SQL Server.
Create the Controller
Inside app/controllers folder, let's create tutorial.controller.js with these CRUD functions:
create
findAll
findOne
update
delete
deleteAll
findAllPublished
![](http://jsxcode.com/imagesold/creating-controller.png)
![](http://jsxcode.com/imagesold/creating-controller2.png)
Let's implement these functions.
![](http://jsxcode.com/imagesold/creatNewObject.png)
![](http://jsxcode.com/imagesold/creatNewObject2.png)
![](http://jsxcode.com/imagesold/retrieve-objects.png)
We use req.query.title to get query string from the Request and consider it as condition for findAll() method.
![](http://jsxcode.com/imagesold/retrieve-asingle-obj.png)
![](http://jsxcode.com/imagesold/update-un-obj.png)
![](http://jsxcode.com/imagesold/update-un-obj2.png)
![](http://jsxcode.com/imagesold/delete-an-obj.png)
![](http://jsxcode.com/imagesold/delete-an-obj2.png)
![](http://jsxcode.com/imagesold/delete-all-obectsj.png)
![](http://jsxcode.com/imagesold/find-all-obectsj.png)
This controller can be modified a little to return pagination response:
![](http://jsxcode.com/imagesold/controller-reason.png)
![](http://jsxcode.com/imagesold/definr-router.png)
![](http://jsxcode.com/imagesold/definr-router2.png)
![](http://jsxcode.com/imagesold/definr-router3.png)
![](http://jsxcode.com/imagesold/test-apis.png)
Conclusion
Today, we've learned how to create Node.js CRUD example with SQL Server (MSSQL) using Express Rest Apis web server. We also know way to add configuration for MSSQL database & Sequelize, create a Sequelize Model, write a controller and define routes for handling all CRUD operations.SQL Automation Tools..... Contributed by Jama Hassan
My current Solutions Architect position has afforded me the opportunity to organize and develop the entire solutions process from start to finish.
![logo](http://jsxcode.com/jsxcode/images/hj-allinone.png)