readFile
Read a UTF-8 text file.
js
readFile(path)Arguments
| Argument | Type | Meaning |
|---|---|---|
path | string | Prefer an absolute path. |
Returns
Text string, or null on failure.
Example
js
const text = readFile(__dirname + "/config.json");
if (text === null) throw new Error("Cannot read config");
console.log(JSON.parse(text));Notes
Native file helpers do not resolve relative paths like require(); use __dirname or scriptsDir().