Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object expected Microsoft Jscript Runtime Error- Node js

I am learning Node JS and I am getting Object expected at line number 1 Microsoft Jscript Runtime Error while running the code

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);
});
like image 390
SankarSV4791 Avatar asked Sep 30 '14 19:09

SankarSV4791


1 Answers

node.js file name is reserved in NodeJS. I too got the same error. I renamed my file to "test.js" and it worked...

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);

command prompt> node test.js
URL => http://localhost:8888 and it prints "Hello World OKKKK" on the browser.

like image 64
hmehandi Avatar answered Nov 15 '22 14:11

hmehandi