SyntaxError: Unexpected token 'catch' in C:\xampp\htdocs\mysite.local\views\index.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
at new Function (<anonymous>)
at Template.compile (C:\xampp\htdocs\mysite.local\node_modules\ejs\lib \ejs.js:661:12)
at Object.compile (C:\xampp\htdocs\mysite.local\node_modules\ejs\lib \ejs.js:396:16)
at handleCache (C:\xampp\htdocs\mysite.local\node_modules\ejs\lib \ejs.js:233:18)
at tryHandleCache (C:\xampp\htdocs\mysite.local\node_modules\ejs\lib \ejs.js:272:16)
at View.exports.renderFile [as engine] (C:\xampp\htdocs\mysite.local\node_modules\ejs\lib \ejs.js:489:10)
at View.render (C:\xampp\htdocs\mysite.local\node_modules\express \lib\view.js:135:8)
at tryRender (C:\xampp\htdocs\mysite.local\node_modules\express \lib\application.js:640:10)
at Function.render (C:\xampp\htdocs\mysite.local\node_modules\express \lib\application.js:592:3)
at ServerResponse.render (C:\xampp\htdocs\mysite.local\node_modules\express \lib\response.js:1012:7)
app.get('/smart', function(req, res) {
var order;
var side;
var prmin;
var prmax;
if(!order){order='name';}
if(!side){side='ASC';}
if(order=='price'){
side=req.cookies.sideprice;
}else if(order=='popularity'){
side=req.cookies.sidepopularity;
}else if(order=='tsale'){
side=req.cookies.side.sidesale;
}
var query;
var smartphopneList=[];
// Connect to MySQL database.
var connection = getMySQLConnection();
// Do the query to get data.
connection.connect();
quer='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,(`price` -`price` / 100 * `sale`) AS `tsale` FROM `smartphone` ORDER BY `tsale` ASC';
connection.query(quer, function(err, rowes, fields) {
// Loop check on each row
prmin=rowes[0].tsale;
prmax=rowes[(rowes.length-1)].tsale;
// Render index.pug page using array
});
if(req.cookies.prmin){
prmin=req.cookies.prmin;
}
if(req.cookies.prmax){
prmax=req.cookies.prmax;
}
if(!prmin){prmin=7000;}
if(!prmax){prmax=20000;}
var otherwhere='';
if(req.cookies.vprodaj=='checked'){
otherwhere=otherwhere+' AND WHERE count>0 ';
}
if(req.cookies.soskidkoi=='checked'){
otherwhere=otherwhere+' AND WHERE (`price` -`price` / 100 * `sale`) >0 ';
}
if(req.cookies.dbesplat=='checked'){
otherwhere=otherwhere+' AND WHERE `dbesplat`=1 ';
}
if(req.cookies.promokodi=='checked'){
otherwhere=otherwhere+' AND WHERE `promokodi`=1 ';
}
if(req.cookies.presents=='checked'){
otherwhere=otherwhere+' AND WHERE `presents`=1 ';
}
if(req.cookies.newtov=='checked' ){
otherwhere=otherwhere+' AND WHERE `newtov`=1 ';
}
if(req.cookies.uctov=='checked'){
otherwhere=otherwhere+' AND WHERE `uctov`=1 ';
}
if(req.cookies.garantprod=='checked'){
otherwhere=otherwhere+' AND WHERE `soskidkoi`>0 ';
}
if(req.cookies.oswin=='checked'){
otherwhere=otherwhere+' AND WHERE `oswin`=1 ';
}
if(req.cookies.osios=='checked'){
otherwhere=otherwhere+' AND WHERE `osios`=1 ';
}
if(req.cookies.osandrod=='checked'){
otherwhere=otherwhere+' AND WHERE `checked`=1 ';
}
if(!otherwhere){
var where='WHERE (`price` -`price` / 100 * `sale`) >= '+prmin+' AND (`price` -`price` / 100 * `sale`) <= '+prmax;
}else{
var where='WHERE (`price` -`price` / 100 * `sale`) >= '+prmin+' AND (`price` -`price` / 100 * `sale`) <= '+prmax +otherwhere;
}
query='SELECT `id`,`prod`,`name`,`description`,`photo`,`price`,`popularity`,`sale`,`dbesplat`,`promokodi`,`presents`,`newtov`,`garantprod`,(`price` -`price` / 100 * `sale`) AS `tsale` FROM `smartphone` '+where+' ORDER BY '+order +' '+side;
connection.query(query, function(err, rows, fields) {
if (err) {
res.status(500).json({"status_code": 500,"status_message": "internal server error"});
console.log(err);
} else {
// Loop check on each row
var rowlenght=rows.length+1;
for (var i = 0; i < rows.length; i++) {
// Create an object to save current row's data
var smartphopne = {
'id':rows[i].id,
'prod':rows[i].prod,
'name':rows[i].name,
'photo':rows[i].photo,
'description':rows[i].description,
'price':rows[i].price,
'sale':rows[i].sale,
'len':rowlenght,
'tsale':rows[i].tsale,
'prmin':prmin,
'prmax':prmax,
'cprmin':req.cookies.prmin,
'cprmax':req.cookies.prmax,
'vprodaj':req.cookies.vprodaj,
'soskidkoi':req.cookies.soskidkoi,
'dbesplat':req.cookies.dbesplat,
'promokodi':req.cookies.promokodi,
'presents':req.cookies.presents,
'newtov':req.cookies.newtov,
'uctov':req.cookies.uctov,
'garantprod':req.cookies.garantprod,
'oswin':req.cookies.oswin,
'osios':req.cookies.osios,
'osandrod':req.cookies.osandrod,
};
// Add object into array
smartphopneList.push(smartphopne);
}
// Render index.pug page using array
res.render('index', {"smartphopneList": smartphopneList});
}
});
// Close the MySQL connection
connection.end();
});