× logo Home HTML CSS Javascript React-App Angular.js logo
logo

Node.js Express Back-end Overview




These are APIs that Node.js Express App will export:

Project Structure

* db.config.js exports configuring parameters for MySQL connection & Sequelize.

* Express web server in server.js where we configure CORS, initialize & run Express REST APIs.

* Next, we add configuration for MySQL database in models/index.js, create Sequelize data model in models/tutorial.model.js.

* Tutorial controller in controllers.

* Routes for handling all CRUD operations (including custom finder) in tutorial.routes.js.

This backend works well with frontend in this tutorial.

Implementation

Create Node.js App
First, we create a folder:

$ mkdir nodejs-express-sequelize-mysql
$ cd nodejs-express-sequelize-mysql.

Next, we initialize the Node.js App with a package.json file:

npm init

name: (nodejs-express-sequelize-mysql)
version: (1.0.0)
description: Node.js Rest Apis with Express, Sequelize & MySQL.
entry point: (index.js) server.js
test command:
git repository:
keywords: nodejs, express, sequelize, mysql, rest, api
author: Jama Hassan
license: (ISC)
Is this ok? (yes) yes

We need to install necessary modules: express, sequelize, mysql2 and cors. Run the command:

npm install express sequelize mysql2 cors --save

logo