Reputation: 2887
I use the following code to read txt file from my C drive and I got error
fs = require('fs')
var path = require('path');
var filePath = path.join(__dirname, 'C://nodeTest//test.txt');
fs.readFile(filePath, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
});
in addition I try like following with the same error
fs.readFile('C://nodeTest//test.txt', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
});
error is
Error: ENOENT, open 'C:\nodeTest\test']
errno: -4058,
code: 'ENOENT',
My project is under the following path
C:\Users\C015869\WebstormProjects\myApp\server.js
Upvotes: 0
Views: 3635
Reputation: 2416
Upvotes: 2
Reputation: 1404
You can only read from the webserver. If the file isn't somewhere in the webserver directory or subdirectories you can't read it. If the webserver directory is nodeTest
then just use:
fs = require('fs')
var path = require('path');
var filePath = path.join(__dirname, 'test.txt');
fs.readFile(filePath, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
});
Upvotes: -1