Monday, 11 November 2019

using node js to dynamically change content from database when page reloads

I need node.js to dynamically change the content of website which is fetched from database when page refreshes.So, what I want is that when web page refreshes the images that user has uploaded to database shows on web page.Whenever a user uploads a picture to database it's address is added to database and picture also gets uploaded on server, but the image doesn't show right on webpage until i restart the node.js server.Only database rows gets updated when page reloads.​app.get('/',(req,res)=>{ connection.query("SELECT * FROM images",(error,rows,fields)=>{ if(!!error){ console.log("query not successfull"); } else{ console.log("connected to images table"); for(var i=rows.length-1;i>=0;i--){ adddress.push(rows[i].image); imageRows=rows.length; } res.render('index',{ address:adddress, imageRowsSize:imageRows, linebreaker:'
' }); } }); });

Submitted November 11, 2019 at 03:30PM by salmanahmad_10

No comments:

Post a Comment