Sunday 30 June 2019

EONET error when I can see the file it says is missing in it's folder!

I'm trying to learn node.js using this program and I'm super stuck at asynchronous I/O. Specifically, I'm using fs.readFile on a file named number.txt (saved in the same directory I'm currently in), and the code is running, but when I console.log(err) it says [Error: ENOENT: no such file or directory, open 'C:\Users\myname\javascripting\number.json'].I have a file named number.json saved in the path, C:\Users\myname\javascripting so I don't know why the program can't find it.My code aio.js:var fs = require('fs') var myNumber = undefined function addOne() { fs.readFile('number.json', function doneReading(err, fileContents) { if (err){ console.log('fuck'); console.log(err); } else{ myNumber = parseInt(fileContents) myNumber++ console.log(myNumber)} }) } addOne(); The result when I run in the console C:\Users\myname\javascripting> node aio.js :fuck{ [Error: ENOENT: no such file or directory, open 'C:\Users\myname\javascripting\number.json']errno: -4058,code: 'ENOENT',syscall: 'open',path: 'C:\\Users\\myname\\javascripting\\number.json' }​edit: I've tried the same thing but with number.txt as well

Submitted June 30, 2019 at 06:03PM by reallyageek

No comments:

Post a Comment