Hello I'm thinking if there is any way to load HTML inside node.js as a

正规365体育投注string in app.get("/html") Like "<-html->blabla"... A normal but inside the node.js code Cuz I want to put database values inside it not static is there any way to do that? or at least do what I'm looking for

  • You could store it in a variable? – Darryl Morley Mar 26 at 23:36
  • Yes exactly and then load it inside the page when call the url As lets say i have route app.get and then when i load the html I want something like "html code"+Count Of Something From DataBase variable+"html Code" – Nah Mar 26 at 23:40
  • Which will make it not static anymore – Nah Mar 26 at 23:41
  • Sounds like you either want a template engine, or a DOM implementation. – Brad Mar 26 at 23:42
  • Btw this is the first time i load html inside node.js I have no idea what it could be i know it could from a file but i want inside the node.js – Nah Mar 26 at 23:42

To send a formatted string with express.js正规365体育投注, you can do:

app.get("/html", async (req, res) => {
    const msg = await getMsgFromDB(); // An example of how you fetch data from DB
    res.send(`<!DOCTYPE html>${msg}</html>`);
|improve this answer|||||
  • Wah thank you ill try it now ! – Nah Mar 26 at 23:44
  • I have a question can i use <script> with this? – Nah Mar 26 at 23:45
  • @Nah of course. – Alexandre Senges Mar 26 at 23:55
  • Bro, you forgot the closing ); at last line thank you btw so much! If anyone never used node.js just put at last line ); <3 – Nah Mar 27 at 0:42
  • @Nah nice catch, I fixed it – Alexandre Senges Mar 27 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy正规365体育投注

Not the answer you're looking for? Browse other questions tagged or ask your own question.