I looked up my problem and found this Express res.render is not rendering the page none of the answers helped and none of the others on google worked. I am trying to push a post request with a button that renders a partial ejs file to the screen. It will later get deleted and replaced when i add another button but that is a task for next time. No error is given. The client console.log works and the server console.log works.
here is my server js
const { request } = require('express')
const express = require('express')
const app = express()
app.set('view engine','ejs')
app.use(express.static('public'))
app.use(express.json({limit: '1mb'}))
app.get('/',(req,res)=>{
res.render('layout')
})
app.post('/',async(req,res)=>{
try {
res.render('./partials/hi')
} catch (error) {
console.log(error)
}
})
app.listen(5000,()=>{
console.log('server listening')
})
here is my main js (vanilla js)
const button = document.getElementById('button')
button.addEventListener('click',()=>{
// const hi = document.createElement(<%-require('../views/partials/hi.ejs')%>)
// document.appendChild(hi)
console.log('no')
const options = {
method : 'POST',
}
fetch('/', options)
})
here is the zip file (safe) https://drive.google.com/file/d/1Vwu7VDv613hRKFCZQhBNbONaT4Dk_0x1/view?usp=sharing
The answer is it isnt possible guys
backend should only send data and dosent send pages that well why is ejs a thing i dont know but i wasnt going to work how i wanted to use it the answer is to build api and html separte and learn fetch and use it to call api and loop through api data