Advanced Input/output
const fs = require('fs');
// Read input from a file
fs.readFile('input.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});const fs = require('fs');
// Write output to a file
fs.writeFile('output.txt', 'Hello, world!', (err) => {
if (err) throw err;
console.log('Output written to file!');
});<!DOCTYPE html>
<html>
<head>
<title>Input/output example</title>
</head>
<body>
<form>
<label>Enter your name:</label>
<input type="text" id="nameInput">
<button type="button" onclick="sayHello()">Say hello</button>
</form>
<p id="output"></p>
<script>
function sayHello() {
const name = document.getElementById('nameInput').value;
document.getElementById('output').innerText = `Hello, ${name}!`;
}
</script>
</body>
</html>Last updated