我正在学习Node JS,我在运行代码时遇到第1行Microsoft Jscript运行时错误的对象
var fs = require('fs');
function FileObject () {
this.filename = null;
this.exists = function(callback) {
var self = this;
fs.open(this.filename, 'r', function(err, handle){
if(err){
console.log(self.filename+ 'does Not exist');
callback(false);
}
else {
console.log(self.filename+ 'does Exist Indeed');
callback(true);
fs.close(handle);
}
});
};
}
var fo = new FileObject();
fo.filename = 'doesnotexist';
fo.exists(function(does_it_exist) {
console.log('results from exists:' + does_it_exist);
});
答案 0 :(得分:11)
node.js
文件名。我也得到了同样的错误。我将我的文件重命名为" test.js"它起作用了......
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World OKKK");
response.end();
}).listen(8888);
命令提示符> node test.js
URL => http://localhost:8888它打印了#Hello Manager OKKKK"在浏览器上。
答案 1 :(得分:-1)
您不能双击源文件来运行它,您需要从命令行执行脚本(例如C:\> node foo\bar.js
,假设您的脚本bar.js
在C:\foo
)