0

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.

3
  • No, it does not. You can connect from your code directly to MySQL without any ORM. Commented Jun 27, 2018 at 11:15
  • no, unless you want to use ORMs. you can search to simple module in npmjs.com to handle data connection and other raw things. And then just write SQL queries. If you prefer to use ORM - you may find also few I believe. Commented Jun 27, 2018 at 11:16
  • I want to use MySQL with nodeJS directly, but I don't know if it is possible or not on my project ? Commented Jun 27, 2018 at 11:19

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@CodeLover Not sure what you meant by your comment, but I assume you wanted the post edited with the code using the library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.