简体   繁体   中英

Integration of MySQL with NodeJS Backend and ReactJS FrontEnd

I want to develop an ERP application with ReactJs in FrontEnd, NodeJS in BackEnd and MySQL for the database.

My ERP is also the management of customers, suppliers, purchase orders, delivery notes and products.

I want to know about the integration of MySQL with NodeJS does it require ORM models like Sequelize?

Thanks in advance.

There is no absolute need for an ORM. You can install the mysql driver for node.js through npm and include it in your project. The documentation can be found here: https://www.npmjs.com/package/mysql

You could implement it like this:

var sql = require('mssql');

var config = {
    user: "databaseAccountUsername",
    password: "databaseAccountPassword",
    server: "databaseServerAddress",
    database: "databaseName",
    options: {
        encrypt: false
    }
}

const pool = new sql.ConnectionPool(config);
    pool.connect(err => {
    if(err) {
        console.log(err)
    }
});

function getCustomers() {
    var request = new sql.Request(pool);
    request.query("SELECT customer_id, first_name FROM customers")
    .then((result) => {
        res.end(JSON.stringify(result.recordsets[0]));
    })
    sql.close();
}

I suggest making your queries in your routes and handling them with express or any other request/response library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM