Load File
The loadFile()
function is a core utility in the Nexo Maker API that allows your expansion to read any file stored within its directory. It’s commonly used to load:
HTML templates
CSS stylesheets
JSON configuration files
Static text or data files
This function is asynchronous and returns the file contents as a string or buffer, depending on the encoding.
📘 Syntax
await api.nexomaker.loadFile(path, encoding)
🧩 Parameters
path
string
✅
The full file path (usually using __dirname
)
encoding
string
❌
The file encoding to use (e.g., "utf-8"
). If omitted, returns a buffer.
📤 Returns
With encoding: Returns a
string
containing the file’s contents.Without encoding: Returns a
Buffer
(for binary data).
✅ Example: Reading a JSON File
const jsonString = await api.nexomaker.loadFile(__dirname + "/config.json", "utf-8");
const config = JSON.parse(jsonString);
✅ Example: Injecting HTML + CSS into a Component
const html = await api.nexomaker.loadFile(__dirname + "/doc.html", "utf-8");
const css = await api.nexomaker.loadFile(__dirname + "/style.css", "utf-8");
const styledComponent = await api.nexomaker.defineStyle({
htmldoc: html,
styledoc: css
});
api.nexomaker.postSidebarIcon({
button: "Docs",
key: "custom-docs",
icon: await api.nexomaker.imgconvert(__dirname + "/assets/icon.png"),
route: "/docs",
component: styledComponent
});
⚠️ Notes
Always use
__dirname
to ensure compatibility across different systems.Make sure the file exists to avoid read errors.
You must specify
"utf-8"
encoding if you want to receive the file as a readable string.
💡 Common Use Cases
Load custom HTML and CSS for styled components
Read plugin configuration files
Access static markdown, JSON, or asset metadata
Parse external data and templates
Last updated