Database, problem with require

I should read from a database (I used xaamp with a mysql database). I put this code in Function (node), but I'm having problems with 'require'. I followed the guide to add external modules, but I can't solve it. Could anyone show some examples of database reading?

var mysql = require('mysql');

var connection = mysql.createConnection( {  host : 'localhost',
  user : 'nome_utente',
  password : 'password_utente',
  database : 'nome_db'
} );

var queryString = 'SELECT cmp FROM tbl ORDER By id DESC';

connection.query(queryString, function(err, rows, fields) {
  if (err) throw err;
  for (var i in rows) {
      console.log('Valori: ', rows[i].cmp);


I use MySQL. I use the MySQL node.
It is very easy. No 'require' at all.
msg.topic has the select statement and it just works.

1 Like

Thanks, your solution is certainly more efficient!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.