0

Hi I am trying to implement some js into my ejs script I GET 404 whenever I run it and I know there are similar questions here but the solutions do not work for me I also tried to just add it as a script to ejs but that will not work with my database.

I left out the mongoose connections for shortness

THIS IS MY JS

const express = require('express')
const app = express()
const ejsMate = require('ejs-mate')
const flash_card = require('../../models/FlashCardSchema')
const mongoose = require('mongoose')
const { db } = require('../../models/FlashCardSchema');



console.log('I am working 2');

document.getElementById("quizStart").addEventListener("click", function() {
    document.getElementById("demo").innerHTML = "Hello World";
})

THIS IS MY EJS

<button id="quizStart">Start quiz</button>
<h2>Question 1</h2>
<div>
    <h2 id="question">question</h2>
    <input type="text" name="answer" id="answer">

</div>

<script>
    console.log('I am working');
</script>
<script type="text/javascript" src="/views/Quiz.js"></script>
**THIS IS MY INDEX**
const express = require('express')
const app = express()
const path = require('path');
const ejsMate = require('ejs-mate')
const flash_card = require('./models/FlashCardSchema')
const mongoose = require('mongoose')
const methodOverride = require('method-override');
const { db } = require('./models/FlashCardSchema');

app.engine('ejs', ejsMate)
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs')
app.use(express.urlencoded({ extended: true }))
app.use(methodOverride('method'))
  • 1
    Don't confuse JavaScript which runs on the server with JavaScript which runs in the browser. They are two different programs even if they are written in the same programming language. You can't import modules into browser-side JS when those modules depend on features that only Node provides. – Quentin May 14 '21 at 19:10
  • I am sorry but I just want to embed js into an ejs file and nothing is working. The question that was tagged does not fix any of my issues as far as I can read. – Frank Peterson May 15 '21 at 00:32

0 Answers0