Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WHATWG file URL doc examples https://github.com/nodejs/node/pull/12670
'use strict';
const fs = require('fs');
const { URL } = require('url');
const hosts_file_url = new URL(`file://hostname/p/a/t/h/file.txt`);
fs.readFile(hosts_file_url, 'utf-8', (err,data) => {
if (err) throw err; // error is throw
console.log(data);
});
'use strict';
const fs = require('fs');
const { URL } = require('url');
const hosts_file_url = new URL(`file://hostname/p/a/t/h/file.txt`); // path convereted to UNC
fs.readFile(hosts_file_url, 'utf-8', (err,data) => {
if (err) throw err;
console.log(data); // read file's content
});
'use strict';
const fs = require('fs');
const { URL } = require('url');
const hosts_file_url = new URL('file:///etc/hosts');
fs.readFile(hosts_file_url, 'utf-8', (err,data) => {
if (err) throw err;
console.log(data);
});
'use strict';
const fs = require('fs');
const { URL } = require('url');
const hosts_file_url = new URL(`file:///${process.env['SystemRoot']}/System32/drivers/etc/hosts`);
fs.readFile(hosts_file_url, 'utf-8', (err,data) => {
if (err) throw err;
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.