So, I served an html
page with a node.js
file, and I want to know how I can get an element in the html
file in that node.js
file.
I have tried youtube and google and can't find what I am looking for.
Here is my code:
HTML
<!DOCTYPE html>
<html>
<head></head>
<body>
<p id='iwwinm'>I want to be stored in a node.js var? How?!</p>
</body>
</html>
Node.js
const http = require('http')
const fs = require('fs')
__dirname = path.resolve();
let server = http.createServer(function(req,res) {
console.log('req made: ' + req.url)
res.writeHead(200, {'Content-Type': 'text/html'});
var mRS = fs.createReadStream(__dirname + '/index.html', 'utf8');
mRS.pipe(res)
})
function log() {
console.log('hi')
}
server.listen(3000)
In the end, I simply want to get the content of that p
element, and log it in the node.js
console!