I'm trying to send a variable from nodejs(expressjs) to html page with ejs. But i'm getting ReferenceError: ...... variable is not defined error.
folder structure:
node_modules
src
static-pages-server
views
pages
partials
journey-analize-report.ejs:
<script type="text/javascript">
console.log('<%-currentCulture%>');
</script>
static-pages-server.js:
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const ejs = require('ejs');
var path = require('path');
var currentCulture;
app.get('/', function(req, res) {
res.render("pages/journey-analize-report", {currentCulture:"Hello"});
});
Error:
ReferenceError: D:\Project-UI\views\pages\journey-analize-report.ejs:46
44| <script type="text/javascript">
45|
>> 46| console.log('<%-currentCulture%>');
47|
currentCulture is not defined
at eval (eval at compile (D:\SeyirMobilNG-UI\node_modules\ejs\lib\ejs.js:662:12), <anonymous>:12:16)
at journey-analize-report (D:\SeyirMobilNG-UI\node_modules\ejs\lib\ejs.js:692:17)
at tryHandleCache (D:\SeyirMobilNG-UI\node_modules\ejs\lib\ejs.js:272:36)
at View.exports.renderFile [as engine] (D:\SeyirMobilNG-UI\node_modules\ejs\lib\ejs.js:489:10)
at View.render (D:\SeyirMobilNG-UI\node_modules\express\lib\view.js:135:8)
at tryRender (D:\SeyirMobilNG-UI\node_modules\express\lib\application.js:640:10)
at Function.render (D:\SeyirMobilNG-UI\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (D:\SeyirMobilNG-UI\node_modules\express\lib\response.js:1012:7)
at D:\SeyirMobilNG-UI\static-page-server\static-pages-server.js:41:9
at Layer.handle [as handle_request] (D:\SeyirMobilNG-UI\node_modules\express\lib\router\layer.js:95:5)
I think you should use this syntax
<%= currentCulture %>
But you used
<%-currentCulture%>