I would like to know how to pass variables in Node.js
When I try to fetch and pass some variables to ejs,error something like below has occured.
27| <div id="content">
>> 29| <%=json%>
30| </div>
json is not defined
My current work is like below. Are there any problem? If somone has opinion,please let me know. Thanks
const fetch = require("node-fetch");
const express = require("express");
const app = express();
const API_KEY="https://opentdb.com/api.php?amount=1&type=multiple";
app.get('/', (req, res) => {
fetch(API_KEY)
.then(response => response.json())
.then(json => {
console.log(json);
res.render("quiz.ejs", json);
});
});
app.listen(8080,()=>{
console.log('server is running!');
});
<div id="content">
<%= json %>
</div>