[Solved] “callback is not defined” in node js


You don’t need a callback in this case, because you’re at the end of your route, so to speak.

So instead, you could do something like handle it with sending an error message to your rendered page.

var express = require('express');
var router = express.Router();
var mysql_db = require('../db/db_con')();
var pool = mysql_db.init();
/* GET home page. */
router.get("https://stackoverflow.com/", function(req, res, next) {
    pool.getConnection(function (err,conn) {
        if(err) {
            if(conn) {
                conn.release();
            }
            res.render('board',{rows: [],error:'Could not connect'});
        }else{
          var sql = "SELECT * FROM board";
          var exec = conn.query(sql,[] ,function(err, rows) {
              conn.release();
              if (err) throw err;
              res.render('board', { rows: rows });
        });
      }
    });
});

solved “callback is not defined” in node js