Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: missing posix/win fileURLtoPath alternative #51609

Closed
mcollina opened this issue Jan 30, 2024 · 3 comments · Fixed by #52509
Closed

url: missing posix/win fileURLtoPath alternative #51609

mcollina opened this issue Jan 30, 2024 · 3 comments · Fixed by #52509

Comments

@mcollina
Copy link
Member

Currently url.fileURLtoPath produces different output based on the operating system the program is ran on.

I couldn't find an helper similar to path.posix or path.win32.

@Shreyas-29
Copy link

To solve this issue of: url.fileURLtoPath, you can use this function to create platform-independent file URLs. Here's an example how you can use it:

const url = require('url');

const filePath = 'your/file/path';

const fileUrl = url.pathToFileURL(filePath); // convert file path to file a file URL

const filePathFromUrl = url.fileURLtoPath(fileUrl); // convert file URL back to the file path

console.log('Original file path:', filePath);
console.log('File path from URL:', filePathFromUrl); 

Make sure to replace your/file/path with the actual path you want to convert.

Check this might work. 😊

@LiviaMedeiros
Copy link
Contributor

Are there common usecases where url.pathToFileURL() or url.fileURLToPath() are needed, but path module is not?

IMHO these functions belong to path more than to url, and it would make sense to export them on path.posix and path.win32 (and perhaps either re-export or move default version to path), rather than adding optional params or adding url.posix/url.win32.

@avivkeller
Copy link
Member

In my initial idea for #52509, I tried to move them, but I decided against it for a few reasons:

  1. It's a semver major change (breaking)
  2. They rely on internal URL features that are exported, so moving them would require a rethink of that system

I'm totally for the potential move, I'm just not sure the best way to do it.

avivkeller added a commit to avivkeller/node that referenced this issue Apr 17, 2024
avivkeller added a commit to avivkeller/node that referenced this issue Apr 17, 2024
avivkeller added a commit to avivkeller/node that referenced this issue Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants