Allows a user to do network drive stuff on Microsoft Windows from node js
$ npm install windows-network-drive
- Mount a network drive that will persist after reboot
- Unmount a network drive
- Get a list of all network drives
- Find if a path is already mounted and get the drive letter
- Convert Unix paths to Windows friendly paths
All examples assume:
let networkDrive = require('windows-network-drive');
Finds if a path is already mounted and returns all drive letters that point to that exact path.
find(drivePath: string): Promise<string[]>
networkDrive.find("\\\\DoesExist\\Path")
.then(function (driveLetter)
{
// driveLetter === ["Z"]
});
networkDrive.find("\\\\DoesExist\\Path\\ThisFolderIsNotPartOfTheMountPath")
.then(function (driveLetter)
{
// driveLetter === []
});
networkDrive.find("\\\\DoesNOTExist\\Path")
.then(function (driveLetter)
{
// driveLetter === []
});
List all network drives and their paths.
list(void): Promise<object>
// With network drives
networkDrive.list()
.then(function (drives)
{
/*
drives = {
"F":"\\\\DoesExist\\Path\\Files",
"K":"\\\\NETWORKB\\DRIVE C"
}
*/
});
// No network drives
networkDrive.list()
.then(function (drives)
{
// drives = {}
});
Mounts a network drive path and returns the new drive letter.
mount(drivePath: string, driveLetter?: string, username?: string, password?: string): Promise<string>
networkDrive.mount("\\\\DoesExist\\Path\\Files", "F", undefined, undefined)
.then(function (driveLetter)
{
// driveLetter = "F"
});
Unmounts a network drive.
unmount(driveLetter: string): Promise<void>
networkDrive.unmount("F")
.then(function ()
{
// done
});
Converts a valid file system path to a Windows friendly path.
NOTE: All methods can take in a non Windows friendly path. This is exported for user convenience.
pathToWindowsPath(drivePath: string): Promise<string>
networkDrive.pathToWindowsPath(//DoesExist/Path/Files)
.then(function (windowsPath)
{
// windowsPath = \\\\DoesExist\\Path\\Files
});
Test the current OS is Windows.
isWinOs(void): boolean
if (true ===networkDrive.isWinOs())
{
console.log("This is running on Windows");
}
For more examples, check out the example folder in the GitHub repo!
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
In lieu of a formal style guide, take care to maintain the existing coding style. Format code with VS Code. Add unit tests for any new or changed functionality. Lint and test your code.
Author and list of all contributors can be found in package.json