First of all, I want you to see there.
index.js quote
webdata = (fs.readFileSync(__dirname + '/web/wiki.html', 'utf8'));
webdata=String(webdata)
webdata = webdata.replace('{tmp.data.name}',articlesname);
res.end(webdata);
web/wiki.html
<!DOCTYPE HTML>
<html>
<head>
...
</head>
<body>
<h2>${tmp.data.name}</h2>
<hr>
<br>
<div id="article">
:
:
</body>
</html>
Next, I will explain what I want to do.
I want to use replace to read the string "$ {tmp.data.name}" in HTML and use Node.js Express to make it the content of a variable.
However,
webdata=String(webdata)
webdata = webdata.replace('{tmp.data.name}',articlesname);
does not work.
Variables are defined.
Also, I couldn't try it with a string instead of a variable.
Please help me...
Top comments (1)
Hey @tsumuri1017,
I strongly recommend to use a view engine and render page dynamically.
To use ejs as your view engine in express you need install the ejs package via npm
1:
npm install ejs@3.1.6
2: Set your view engine in your server side
ie your index.js
3: Rename your
wiki.html
towiki.ejs
and rewrite wiki.ejs to4: Render the ejs file on server side
And this should fix your issue.
For more on ejs and express read here
Hope this helps...