フォームデータを別のhtmlページに表示しようとしています。これは私のserver.jsnode.jsサーバーからhtmlページへのデータ表示
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var path=require('path');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, '/')));
app.post('/myaction.html', function(req, res) {
res.send('You sent the name "' + req.body.name + '".');
});
app.listen(8080, function() {
console.log('Server running at http://127.0.0.1:8080/');
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo Form</title>
</head>
<body>
<div id="contact">
<h1>Enter the values</h1>
<form action="/myaction.html" method="post">
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your full name" />
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter your email address" />
<label for="message">Message:</label>
<textarea id="message" placeholder="What's on your mind?"></textarea>
<input type="submit" value="Send message" />
</fieldset>
</form>
</div>
</body>
</html>
あり、それが正常に動作していると名前がに反映されますmyaction.htmlページしかし、私は 'myaction.html'ページを少し書式化してより見やすくしたいと思っています。 HTMLタグやテキストをページに追加したり、既存のページにフォームデータを表示する方法はありますか?
https://expressjs.com/en/guide/using-template-engines.html – Quentin