Ensures a UNC path that requires a user name and password is ready to use in Windows before use.
npm install @cityssm/windows-unc-path-connect
import { connectToUncPath } from '@cityssm/windows-unc-path-connect'
const uncPath = '\\\\server\\fileShare'
/*
* Connect to share
*/
const success = connectToUncPath(
{
uncPath,
userName: 'user',
password: 'p@ss'
},
{
// Attempt to clean up connection on application shutdown
deleteOnExit: true
}
)
/*
* Reading files should now work.
*/
try {
const files = await fs.readdir(uncPath)
} catch (error) {}