bubbleChaser
bubbleChaser

Reputation: 925

In Windows, Node.js' path.join() prepends the current working directory's drive letter(C:\) automatically

I'm using Node.js' path.join() to generate the path in Windows.

const path = require('path');
const myDestPath = path.join('/D', 'test.txt');  // D drive

This results in C:\D\test.txt, prepending the current working directory's drive letter (C:\) automatically, which is not what I want.

How do I go about setting the different drive letter other than C:\ in Node.js?

I've tried path.resolve() as well, but got the same result.

Upvotes: 1

Views: 2480

Answers (1)

r7r
r7r

Reputation: 1525

You may need to add extra slash to create path

const path = require('path');
const myDestPath = path.join('D:\\', 'test.txt');  // D drive
console.log(myDestPath)

results in D:\test.txt

Upvotes: 2

Related Questions