Tutorial: “Crud Operation in React.js and MySQL – React Node.js MySQL CRUD Example – Step By Step React, Nodejs and Mysql simple full-stack Application”
In the tutorial, I introduce how to build an “Crud Operation in React.js and MySQL” project with Nodejs RestAPI and the help of Ajax to POST/GET/PUT/DELETE requests with step by step coding examples:
– Nodejs project produces CRUD RestAPIs with MySQL database using the supporting of Sequelize ORM.
– React.js project will consume the Nodejs CRUD RestAPIs by Ajax then show up on Reactjs component’s views.
Now we define Book’s routes in ./app/route/book.route.js file as below code:
module.exports = function(app) {
const books = require('../controller/book.controller.js');
// Retrieve all Books
app.get('/api/books', books.findAll);
// Retrieve a single Book by Id
app.get('/api/books/:bookId', books.findOne);
}
Implement Nodejs Express RestAPI Controller
In the tutorial “Mongoose change _id to id”, we implement Book’s controller in ./app/controller/book.controller.js file as below sourcecode:
const Book = require('../model/book.model.js');
// FETCH all Books
exports.findAll = (req, res) => {
Book.find()
.then(books => {
let returnedBooks = [];
for (let i = 0; i < books.length; i++) {
returnedBooks.push(books[i].transform());
}
res.send(returnedBooks);
}).catch(err => {
res.status(500).send({
message: err.message
});
});
};
// FIND a Book
exports.findOne = (req, res) => {
Book.findById(req.params.bookId)
.then(book => {
if(!book) {
return res.status(404).send({
message: "Book not found with id " + req.params.bookId
});
}
res.send(book.transform());
}).catch(err => {
if(err.kind === 'ObjectId') {
return res.status(404).send({
message: "Book not found with id " + req.params.bookId
});
}
return res.status(500).send({
message: "Error retrieving Book with id " + req.params.bookId
});
});
};
Nodejs Express Server.js
Now we define server.js file for Nodejs/Express server running at 8080 port as below sourcecode:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json())
// Configuring the database
const dbConfig = require('./app/config/mongodb.config.js');
const mongoose = require('mongoose');
const Book = require('./app/model/book.model.js');
mongoose.Promise = global.Promise;
// Connecting to the database
mongoose.connect(dbConfig.url)
.then(() => {
console.log("Successfully connected to MongoDB.");
initial();
}).catch(err => {
console.log('Could not connect to MongoDB.');
process.exit();
});
require('./app/route/book.route.js')(app);
// Create a Server
var server = app.listen(8080, function () {
var host = server.address().address
var port = server.address().port
console.log("App listening at http://%s:%s", host, port)
})
function initial(){
Book.create({
title: "Origin",
author: "Dan Brown",
description: "Origin thrusts Robert Langdon into the dangerous ntersectio of humankind's two most enduring questions",
published: "2017"
});
Book.create({
title: "Happy Potter and the Deathly Hallows",
author: "J.K. Rowling",
description: "The seventh and final novel of the Harry Potter series.",
published: "2007"
});
Book.create({
title: "The 100-Year-Old Man Who Climbed Out the Window and Disappeared",
author: "Jonas Jonasson",
description: "",
published: "2009"
});
}
Tutorial “Node.js Upload Image to Postgresql Example – Node.js RestApi File Upload (Download) Multiple Files/Images to PostgreSQL database – Multer + Sequelize + Ajax”
In the tutorial, I will introduce how to create a “Node.js Upload Image to Postgresql Example” (and Node.js Rest Api File Download) Application with Ajax client to upload/download single or multiple files/images to PostgreSQL database with Sequelize engine an Multer middleware.
– We use Express framework to create a Nodejs RestAPIs.
– We use Multer middleware for uploading images/files to Nodejs server.
– We use Sequelize ORM to store file data to database MySQL/PostgreSQL.
– I draw a full diagram architecture of Nodejs RestAPI Upload Files
– I configure Sequelize ORM and Multer for Uploading files
– I build Nodejs Express RestApi to upload/download files
– I implement fontend with Jquery Ajax RestAPI client.
Tutorial “Upload and Read Excel File in Node.js – Express RestAPI Upload/Import Download/Export Multiple Excel files”
In the tutorial, I will introduce how to build a Nodejs/Express RestAPIs application to upload/import and download/extract data from multiple Excel files to MySQL or PostgreSQL database by:
Express is used to build Nodejs RestApis
Multer is used to upload/download Excel files
Sequelize ORM is used to manipulate data with MySQL/PostgreSQL
Exceljs is used to save data objects to Excel file
Read-excel-file is used to parse Excel file to data objects
Tutorial: ” Angular Client Side Pagination with Nodejs + MySQL – Server Side Pagination in Node.js Angular MySQL database + Express + Sequelize CRUD ”
In the tutorial, I introduce how to build an “Angular 10 Nodejs Pagination RestAPIs Example with MySQL database (Server Side Pagination with filtering and sorting)” project using Express framework and Sequelize crud queries to interact with database’s records.
– Nodejs Express project (server side pagination) produces pagination RestAPIs with MySQL database records using Sequelize CRUD queries.
– Angular 10 project (client side pagination) will consume the Node.js pagination RestAPIs then show up on component’s views.