我无法写writeFile来写文件。它可以找到它是否不在函数中,因此它不是模块,但是当调用函数时,它会导致错误。
[Uncaught TypeError:无法读取属性' writeFile'未定义的]
JS代码:
var fs = require('fs');
var input = document.getElementById('filename');
var fileName = input.value;
function recordToFilename() {
var input = document.getElementById('filename');
var fileName = input.value;
var qw = fileName;
if (qw) {
alert('value of: ' + qw);
console.log(qw);
// demo output
var myObject = {
qw: qw,
fullN: function() {
return this.qw;
}
};
document.getElementById("demo").innerHTML = myObject.fullN();
var path = "danny.txt";
var data1 = "jdsfhadj"
fs.writeFile(path,data1)
//end demo output code
} else {
alert('Please enter a filename!');
input.focus();
}
};
HTML代码:
<html>
<head>
<title>writeFile</title>
<script src="jquery.js"></script>
<script src="bonescript.js"></script>
<script src="test_3.js"></script>
</head>
<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>
答案 0 :(得分:0)
请升级您的节点版本以解决此问题。