How to run nodejs script from ruby ​​on rails in production mode

In my project, I am trying to run a nodejs script from ruby ​​on rails.

Runs in my product_details_controller as follows:

system "node /home/user1/sample.js"

In sample.js, I do like this:

var jsdom = require('/usr/local/lib/node_modules/jsdom'),
    request = require('/usr/local/lib/node_modules/request');
var _mysql = require('/usr/local/lib/node_modules/mysql');
var MYSQL_USER = 'root';
var MYSQL_PASS = 'abc';
var DATABASE = 'example';
var mysql = _mysql.createClient({
    user: MYSQL_USER,
    password: MYSQL_PASS,
});
mysql.query('USE ' + DATABASE);
mysql.query('select * from product_details',
    function selectCb(err, results, fields) {
        if (err) throw err;
        else {
            for (var i in results) {
                var product = results[i];
                console.log(product);
            }
        }
    }); 

In development mode, it works fine. But when I try to deploy it to the server, I run into a problem.

mysql.query ('use' + DATABASE) is not executed, and it only loops. I do not know how to fix this. Please help. In errorlog I also do not get errors. I get no errors and no response. Please help me. Thanks in advance.

+3
source share

No one has answered this question yet.


All Articles