E
E
Erik21212017-09-22 16:48:56
Express.js
Erik2121, 2017-09-22 16:48:56

How to display values ​​in index.html (node.js + express)?

Hey! I'm a beginner and now I'm trying to figure it out, please tell me what to do:
I'm trying to get data from the database and display it in a loop on the page.

app.get('/', function(req, res) {
    connection.query("SELECT * FROM mini",  function(err, rows) {
        if(err) throw err;
        res.render('index.html', { data: rows });
  });
});

<div class="example"></div>
How to finally display the data object on the html page?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Abcdefgk, 2017-09-22
@Erik2121

A method is a packaged (for convenience) something like this:res.render('file')

var jade = require('jade');
var htmlText = jade.renderFile('./file.jade', { ... });
res.send(htmlText);

Check out some Express templating engine.

O
oh, 2017-09-22
well @AnneSmith

take any finished project on github and see how it's done,
or are you going to ask about every comma here?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question