Javascript:
const express = require("express");
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
/**
* html seite
*/
app.get('/index', (req, res) =>{
res.sendFile(__dirname + "/public/index.html");
var name = "Nene";
res.send(name);
});
/**
* Port
*/
app.listen(3000, function(){
console.log("Server started on port 3000...")
});
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>knowladgebase</title>
</head>
<h1>Article</h1>
<body>
<p id="p1">
<script>
</script>
</p>
</body>
<footer>
<br>
<hr>
<p>© Copyrigth</p>
</footer>
</html>
Ich mach Einarbeit in Node.js, ich wollte z.B ein Variable "Nene" an html "index.html" senden und dann diese Variable auf html-seite auslesen.
Wie kann man das machen.
Vielen Dank im Voraus