Javascript 在node.js和mysql workbench之间建立数据库连接

Javascript 在node.js和mysql workbench之间建立数据库连接,javascript,mysql,sql,node.js,angular,Javascript,Mysql,Sql,Node.js,Angular,我正在学习一个现成的应用程序,我正在尝试建立连接,以便应用程序开始工作并保存数据 我完成了康涅狄格大学的课程,还制作了一个“员工数据库”,其中包含我需要的两个表 服务器在本地主机3000上运行,前端在端口4200上侦听。这是连接和创建数据库/模式的代码 config.json { "host": "localhost", "user": "cveto", "database": &

我正在学习一个现成的应用程序,我正在尝试建立连接,以便应用程序开始工作并保存数据

我完成了康涅狄格大学的课程,还制作了一个“员工数据库”,其中包含我需要的两个表

服务器在本地主机3000上运行,前端在端口4200上侦听。这是连接和创建数据库/模式的代码

config.json

{
  "host": "localhost",
  "user": "cveto",
  "database": "employees",
  "password": "1234567"
}
database.js创建池

const mysql = require('mysql2');

const config = require('../config/config.json');

const pool = mysql.createPool({
  host: config.host,
  user: config.user,
  database: config.database,
  password: config.password,
});

module.exports = pool.promise();
以及一些查询模型

const db = require('../util/database');

module.exports = class Employee {
  constructor(names, address, number, salary) {
    this.names = names;
    this.address = address;
    this.number = number;
    this.salary = salary;
  }

  static fetchAll() {
    return db.execute('SELECT * FROM employees');
  }

  static save(employee) {
    return db.execute(
      'INSERT INTO employees (names, address, number, salary) VALUES (?, ?, ?, ?)',
      [employee.names, employee.address, employee.number, employee.salary]
    );
  }

  static delete(id) {
    return db.execute('DELETE FROM employees WHERE id = ?', [id]);
  }
};
我只想知道如何建立连接,使应用程序正常工作,并将用户和新员工保存到我的数据库中。代码来自公共存储库,因此代码正在工作,现在来自数据库或服务器连接的代码