при запуске ноды выдает такие ошибки
D:\app>nodemon app.js
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
node express work on 3000
D:\app\app.js:34
if (error) throw err;
^
ReferenceError: err is not defined
at Query.<anonymous> (D:\app\app.js:34:18)
at Query.<anonymous> (D:\app\node_modules\mysql\lib\Connection.js:526:1 0)
at Query._callback (D:\app\node_modules\mysql\lib\Connection.js:488:1 6)
at Query.Sequence.end (D:\app\node_modules\mysql\lib\protocol\sequences\ Sequence.js:83:24)
at D:\app\node_modules\mysql\lib\protocol\Protocol.js :404:18
at Array.forEach (<anonymous>)
at D:\app\node_modules\mysql\lib\protocol\Protocol.js :403:13
at processTicksAndRejections (node:internal/process/task_queues:78:11)
[nodemon] app crashed - waiting for file changes before starting...
Вот так выглядит файл app.js
let express = require('express');
let app = express();
app.use(express.static('public'));
app.set('view engine', 'pug');
let mysql = require('mysql');
let con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'P@ssw0rd',
database : 'market'
});
app.listen(3000, function () {
console.log('node express work on 3000');
});
app.get('/', function (req, res) {
con.query(
'SELECT * FROM goods',
function(error, result){
if (error) throw err;
let goods = {};
for (let i = 0; i < result.length; i++){
goods[result[i]['id']] = result[i];
}
console.log(JSON.parse(JSON.stringify(goods)));
res.render('main', {
foo: 'hello',
bar: 7,
goods : JSON.parse(JSON.stringify(goods))
});
}
);
});