Convert a file path to a file URL: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
JavaScript
63
30 commits
updated Sep 18, 2026
Convert a file path to a file url:
unicorn.jpg→file:///Users/sindresorhus/unicorn.jpg
[!TIP] Node.js supports this built-in now with
url.pathToFileURL(path).
npm install file-url
import fileUrl from 'file-url';
fileUrl('unicorn.jpg');
//=> 'file:///Users/sindresorhus/dev/file-url/unicorn.jpg'
fileUrl('/Users/pony/pics/unicorn.jpg');
//=> 'file:///Users/pony/pics/unicorn.jpg'
fileUrl('unicorn.jpg', {resolve: false});
//=> 'file:///unicorn.jpg'
Returns the filePath converted to a file URL.
It does not support filenames with backslashes.
Type: string
The file path to convert.
Type: object
Type: boolean
Default: true
Passing false will make it not call path.resolve() on the path.
Overall
Maintained
Code review
npm
Latest release
Releases this year
67 followers · starred Jun 2021
Convert a file path to a file URL: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
JavaScript
63
30 commits
updated Sep 18, 2026
Convert a file path to a file url:
unicorn.jpg→file:///Users/sindresorhus/unicorn.jpg
[!TIP] Node.js supports this built-in now with
url.pathToFileURL(path).
npm install file-url
import fileUrl from 'file-url';
fileUrl('unicorn.jpg');
//=> 'file:///Users/sindresorhus/dev/file-url/unicorn.jpg'
fileUrl('/Users/pony/pics/unicorn.jpg');
//=> 'file:///Users/pony/pics/unicorn.jpg'
fileUrl('unicorn.jpg', {resolve: false});
//=> 'file:///unicorn.jpg'
Returns the filePath converted to a file URL.
It does not support filenames with backslashes.
Type: string
The file path to convert.
Type: object
Type: boolean
Default: true
Passing false will make it not call path.resolve() on the path.
Overall
Maintained
Code review
npm
Latest release
Releases this year
67 followers · starred Jun 2021