Fs.writeFile not working properly


#1

fs.writeFile

I keep getting an error Cannot read property ‘writeFile’ of undefined .
When I call it from a function() works fine when not in function.

< !DOCTYPE html >


writeFile





//filestream = require(‘fs’);
var fs = require(‘fs’);
var b = require(‘bonescript’)

		function recordToFilename() {
		var input = document.getElementById('filename');
		var fileName = input.value;
		var qw = fileName;
		var data1 = "jdsfhadj"
		if (fileName) {
		alert('Recording: ' + fileName);
		console.log(qw);
		fs.writeFile('t-danny.txt', 'djdashfdsjhg');
		} else {
		alert('Please enter a filename!');
		input.focus();
		}
		};
	</script>
<body>

	<label for="filename">Filename</label>
	<input name="filename" id="filename" type="text">

		<a id="enter_button" onclick="recordToFilename();" href="javascript:void(0);"
				title="enter">enter name</a>
		<br>
			<p id="demo"></p>


		</body>
	</html>

#2

Please post your code so we can see what’s going wrong. It’s probably an issue with where you’re defining Fs.