Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access file from network share path in nodejs

Tags:

node.js

The path looks like this

\\10.1.10.11\Results\\filename.rtf

From my machine, i can access it just fine by pasting it to Run box, enter username and password.

I've tried smb2 (smb2) but the sample code just hangs and after awhile, I get Error: read ECONNRESET.

I need to make this works on both linux and windows.

like image 310
Tuan Anh Tran Avatar asked Jan 20 '15 02:01

Tuan Anh Tran


2 Answers

I figure I might as well just mount it and access it like local file.

for Linux server, I used smbmount.

like image 134
Tuan Anh Tran Avatar answered Nov 08 '22 07:11

Tuan Anh Tran


Did you escape the backslashes?

 var path = "\\\\10.1.10.11\\Results\\filename.rtf";
 console.log(path);

Above works, but here's a better looking way (that accomplishes the same path without having to double up those backslashes):

let path = String.raw`\\10.1.10.11\Results\filename.rtf`;
console.log(path);

Warning: With this technique, you still have to double up the backslash if the string ends with a backslash.

Doing this, I just had success attaching a file (located on a network share) to an email via node.js (and the nodemailer package). Perhaps this would apply in what you're doing too.

like image 22
Lonnie Best Avatar answered Nov 08 '22 07:11

Lonnie Best