I am trying to do a music player site. I send the static file "Music_file.html" in node JS , after that I use database in nodeJS to get a list of songs related information , and attach it to the class 'song-item'. The content of song-item will be in a string for simplcity. I want to append the string as an innerHTML of the class 'main-page'.
Music_site.html
<html>
<body>
<div class='main-page'>
<div class='song-item'>
<div class='song-item-thumbnail'> <img class='thumbnail' src='./thumbnail/bluedaa.jpg'> </div>
<div class='song-item-song-info'> Blue daa </div>
<div class='song-item-filename'>./songs/bluedaa.mp3</div>
</div>
</div>
</body>
</html>
The file for node JS: loginserver.js
ar http=require('http')
var fs=require('fs')
var querystring=require('querystring')
var nodemailer=require('nodemailer')
var MongoClient=require('mongodb').MongoClient
var express=require('express');
var app = express();
app.get('/' , function(req,res){
res.writeHead(200,{"Content-Type":"text/html"});
fs.createReadStream("signup.html","UTF-8").pipe(res);
}
);
app.use('/', express.static(__dirname) );
//POST function
app.post('/',function(req,res){
var data=""
req.setEncoding('UTF-8')
req.on('data',function(chunk){
data+=chunk;
});
req.on('end',function()
{
})//req.on
res.writeHead(200,{"Content-Type":"text/html"});
fs.createReadStream("./Music_site.html","UTF-8").pipe(res);
/* Get the song information from the database */
/* append it to the class 'main-page' */
});
app.listen(8000);
The pseudocode to get the song info and append it to a string
var content='';
var cur = sqlite3.execute('SELECT * from SONGS');
for row in cur
{
content+="<div class='song-item'> <div class='song-item-thumbnail'> <img class='thumbnail' src=' ";
content+ = row.imgsrc;
content+ = "'> </div> <div class='song-item-song-info'> ";
content+ = row.songname;
content+= "</div> <div class='song-item-filename'> ";
content+ = row.filename;
content+ = "</div> </div>";
}
'.main-page'.append(content);