I have this code:
let http = require('http');
let fs = require('fs');
let handleRequest = (request, response) => {
response.writeHead(200, {
'Content-Type': 'text/html'
});
fs.readFile('./index.html', null, function (error, data) {
if (error) {
response.writeHead(404);
respone.write('Whoops! File not found!');
} else {
response.write(data);
}
response.end();
});
};
http.createServer(handleRequest).listen(8000);
Basically, this code create a local server on Node and open the file: 'index.html'.
Now, I create a <button> on my 'index.html' that when is clicked (onclick) calls a function named 'hello':
function hello() {
console.log('hello world);
}
So, when the button is clicked, a 'hello world' is showed in the browser console, but I want the 'hello world' to be shown in the nodejs console, not browser.
How can I achieve it?
Thanks!
.jsfile and then call it from html.