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
π§© 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
β
Example: Injecting HTML + CSS into a Component
β οΈ 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