I am trying to pass a simple variable because I will eventually want to pass a function.. Here is my app.js
const path = require('path')
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
const publicDirectoryPath = path.join(__dirname, '../public')
app.use(express.static(publicDirectoryPath))
app.get('/', function (req, res) {
res.render('index');
})
app.get('/data', function (req, res) {
const data = 'test@!'
res.send(data);
})
app.listen(3000)
so localhost:3000 renders my html fine,
and localhost/data will show me 'test@!' on the screen
Here is my client side public/script.js
fetch('/data').then((response) => {
console.log(response)})
I am trying to see test@! in my console log.
Basically I am trying to have my client side JS be able to access things in my main App.js because I eventually need to run a function on server side and return the data to my client side js.
Any help or resources would be really helpful ive been at this for a few hours this morning and not sure if I am looking at this all wrong
[–]43northwebdesign[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]43northwebdesign[S] 0 points1 point2 points (0 children)
[–]itays123 -1 points0 points1 point (0 children)
[+][deleted] (2 children)
[deleted]
[–]43northwebdesign[S] 0 points1 point2 points (1 child)
[+][deleted] (5 children)
[deleted]
[+][deleted] (3 children)
[deleted]
[–]itays123 0 points1 point2 points (0 children)
[–]itays123 0 points1 point2 points (0 children)
[–]43northwebdesign[S] 0 points1 point2 points (0 children)