I was trying to display a string on the client-side by fetching the result from serverside but for some reason, it is not displaying the fetched data. When I console log the variable straight on the js file the server successfully prints the string. The program is not exporting the variable to the client-side to display it. I can't figure out where I went wrong. Any help is appreciated. Thanks in advance.
const router = require("express").Router();
const {
  callName
} = require("pathJs");
router.route("PathRoute").get(async(req, res) => {
  const Result = await callName();
  return res.json(Result);
});
module.exports = router;function name() {
  const liner = "this works"
  console.log(liner)
  //updated
  return liner;
}
async function callName() {
  const data1 = await name()
  return data1;
}
callName()<p id="insertHere" style="color: white;"></p>
<script>
  async function caller() {
    await fetch(`http://localhost:5000/api/PATH`)
      .then((res) => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve(res.json())
          }, 1000)
        })
      }).then((response) => {
          console.log(response)
          document.getElementById("insertHere").innerHTML = response.liner
        }
      )
  }
</script>const express = require("express");
const cors = require("cors");
const routePath = require("./routePath");
const {
  response
} = require("express");
require("dotenv").config({
  debug: process.env.DEBUG
});
const port = process.env.PORT || 5000;
const app = express();
app.use(cors());
app.use(express.json());
app.use("/api", routePath);
app.listen(port, () => {
  console.log(`server is running on port: http://localhost:${port}`);
});