Dynamic background using response.send?

Can I send some javascript that will attach a background-image to this html-body in the response.send(?here?) My project has no /views directory or index.html : I prefer to communicate using the background image so I need to set it…

<body><div class="widgetThing"></div></body>
const express = require('express');
const app = express();
var mysql = require('mysql')

app.get('/', function(request, response) {
  var con = mysql.createConnection({
      host: process.env.MYSQL_HOST,
      user: process.env.MYSQL_USER,
      password: process.env.MYSQL_PASSWORD,
      database: process.env.MYSQL_DBNAME,
      port: "3306"

  con.connect(err => {
      } else {
        con.query('', function( err, rows, fields ) {
          if( err ) throw err
          //console.log('From DB: ', rows[0])
        //below populates widgetThing-div
        response.send(`<script id="widget.thing.chat" type="module"src="https://rightyeahok.js?alt=media&workspaceId=XXX&channelId=lobby&mode=newtab" crossorigin></script><script type="text/javascript">//<![CDATA[var i = 10;if (i < 5) {  // some code changes background-image in here?}//]]>var test = 0;</script>`);

// listen for requests :)
const listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);

The first <script> I pass in response.send(<script></script><script></script>) works fine -I’m testing to send a second using these attributes @ https://www.w3schools.com/Tags/tag_script.asp -trying to remember how params can be passed to response.send(param) ?

Hey, I haven’t specifically done this with Node, but you can set the background image with:

document.body.style.backgroundImage = "url('img_tree.png')";
1 Like