Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to access a shared network drive in node.js

How to access a shared network drive in node.js

Problem

In IIS, I have a web service which runs under an Application pool which has the identity of a user that has access to a drive on a Remote Machine. In this way, when the web service runs and it tries access the remote machine to read a file, we do not get any invalid authorization errors.

I have now written my first Node.js app but I am not sure how to allow access to a file stream from the app to the remote machine. I have the unc path name to the remote machine's file I want to read but I am not sure if I have to pass in the credentials of the user to access the file or I have to run the Node.js app under certain credentials.

Any clues?

I know there is node for IIS, but is there another way of doing this without IIS.

Update:

Just ran my app under my user account and this account is configured to allow access to a remote machine and I have access to the remote machine without changing my code (in other words just using the Unc path directly). However, how can I do this using another user's credentials (i.e. impersonation in Node.js?)

Problem courtesy of: JD.

Solution

Node does not handle impersonation like .NET applications do, since Nodejs is not Windows specific, so it does not know about the windows way of handling rights and elevation.

But that is not a problem. I have used the following technique on large financial networks.

As you pointed out yourself, the best solution is to have a dedicated user account for your nodeJS application with sufficient rights to access the UNC, but with no other rights. Then when you run the application, run it as this user.

Let me suggest that your setup a service to run the nodejs application and in the service specify the user account. This makes it much easier and safer. If you application is ever hacked, the hacker will not be able to escape the restrictions of the account.

Solution courtesy of: ExxKA

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to access a shared network drive in node.js

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×