× logo Home HTML CSS Javascript React-App Top-10 Javascript Algorithms logo
logo

Node.js Express Back-end App 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
Enter fullscreen mode Exit fullscreen mode

- Navigate to the project directory: Use the cd command to navigate into the newly created directory:
cd nodejs-express-sequelize-mysql
Enter fullscreen mode Exit fullscreen mode


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


-Initialize a new Node.js project: To initialize a new Node.js project, run the following command in your terminal:
npm init
Enter fullscreen mode Exit fullscreen mode

This command will prompt you to provide information about your project, such as the name, version, description, entry point, etc. You can press enter to accept the default values or provide your own.

{
  "name": "nodejs-express-sequelize-mysql",
    "version": (1.0.0) ,
    "description": "Node.js Rest Apis with Express, Sequelize & MySQL",
    "entry point": "(index.js) server.jsst",
    "strict": true,
    "test command": ,
    "git repository": ,
    "Author": Jama Hassan
  },
  "license": ["(ISC)"],
  "exclude": ["node_modules"]
}
Enter fullscreen mode Exit fullscreen mode

- Install the necessary dependencies: With your project initialized, We need to install the required dependencies. In this case, We need to install necessary modules: express, sequelize, mysql2 and cors.

Run the following command in your terminal to install these dependencies:
npm install express sequelize  mysql2  cors--save
Enter fullscreen mode Exit fullscreen mode
npm install express sequelize mysql2 cors --save

This command will download and install the specified packages and save them as devDependencies in your package.json file.


Full-Stack Engineer