I'm trying to read a text file using NodeJS on a Mac. The file is on a Windows computer which is on the same network.
var fs = require('fs');
var file = "smb://someserver/stuff/names.txt";
fs.readFile(file, 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
When I run this code, I get:
> Error: ENOENT, open 'smb://someserver/stuff/names.txt'
I probably need to authenticate access to the file, but I haven't found any docs or modules that deal with this scenario. Is it possible to read/write files like this?
I've tried using UNC paths (ie \\someserver\stuff\names.txt
) but I believe that is only part of the solution. Somehow I need to supply username/password/domain because this file requires special permission. Is it possible to supply permissions somehow? For example:
var fs = require('fs');
var file = '\\someserver\stuff\names.txt';
var credentials = { username:'mydomain/jsmith', password:'password' }; ???
fs.readFile(file, 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
You should use UNC paths if you are trying to access resources from other network drives.
var fs = require('fs');
var file = "\\someserver\stuff\names.txt";
fs.readFile(file, 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With