У меня есть этот код:
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);
По сути, этот код создает локальный сервер на узле и открывает файл: «index.html».
Теперь я создаю <button>
в моем index.html, который при нажатии (onclick) вызывает функцию с именем 'hello':
function hello() {
console.log('hello world);
}
Итак, когда кнопка нажата,«hello world» отображается в консоли браузера, но я хочу, чтобы «hello world» отображался в консоли nodejs, а не в браузере.
Как мне этого добиться?
Спасибо!