Skip to main content

Posts

Showing posts from October 17, 2022

Let's create a Node.js REST CRUD server with MySql

Greetings! In a previous, I briefly discussed the steps to create a simple REST server using Node.js. In this post, I'm discussing the steps needed to create a restful crud API using Node, Express, and MySql with Sequelize. The complete source code can be found here . What we build We are going to create CRUD operations for books. It is very simple and we don't go too in-depth as the idea is to explore how we can build a restful API with Node and MySql. Steps Create the project Create the express server Define end points and layers Implement endpoints layers Package structure Create the project We will use ES6 features hence babel is used. Nodemon is used to auto-start the server with new changes. npm init -y npm install express body-parser mysql2 sequelize cors --save npm install @babel/core @babel/node @babel/preset-env --save-dev npm install nodemon --save-dev { "name": "nodejs-rest-crud", "version": "1.0.0",

Let's create a simple RESTful CRUD server with Node.js (and fake db)

Greetings RESTful API development is one of the most used use cases for Node.js. We will explore how we can build such an API in this post. As the focus here is on the web layer, I'll use an in-memory data store (an array). Also, I'll use my starter project to save some typing. The source can be found here . What we will build We are going to create CRUD operations for books. It is very simple and we don't go too in-depth as the idea is to create something to play with. Steps Create the project and install dependencies Create the express server Define end points Fill endpoints Create the project and install dependencies npm init -y npm install express body-parser cors --save npm install @babel/core @babel/node @babel/preset-env --save-dev npm install nodemon --save-dev We need to add module type in package.json in order to use ES6 modules. When we import we need to add .js as well. in package.json "type": "module" "scripts":

Let's Setup Babel in Node.js

Greetings! Node.js is one of the most popular and most used backend technologies. It is used by many. I just want to create a project to play with node.js. Hence I thought to create a simple starter project with node.js and express (for myself or anyone who is interested). I would like to use ES6+ features hence I'm using babel here. Other than that, node, express, body-parser, and cors will be added. The source code is here . What is Babel? Bable is a JavaScript transcompiler that is mainly used to convert ES2015+ code into backward-compatible JavaScript code. What that means is we can use newer JavaScript features and babel will transcompile it for us to use in older JavaScript engines. Steps Create the project Install dependencies Setup babel Create the express server Create the project We can initialize a node.js project using npm. npm init -y Install dependencies Let's install our required packages. npm install express body-parser cors --sav