content is undefined,error is Error:ENOENT,open
'C:\Windows\system32\hello.txt'
i just started learning node. and here is my problem,i got sample.js file
var fs=require("fs");
console.log("starting");
fs.readFile("hello.txt" , function(error,data){
console.log("content is asdas " + data);
});
console.log("executed");
and hello.txt with content ,they both are on my desktop
hello
when i run as administrator in powershell or cmd this code
C:\Windows\system32\ node C:\Users\X\Desktop\sample.js
i get
starting
executing
content is asdas undefined
when i log error
var fs=require("fs");
console.log("starting");
fs.readFile("hello.txt" , function(error,data){
console.log("content is asdas " + error);
});
console.log("executed");
i get
starting
executing
content is asdas Error:ENOENT,open 'C:\Windows\system32\hello.txt'
So i guess that error is that node is looking in system32,not in desktop...?
Thanks!
No comments:
Post a Comment