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

Name
Type
Required
Description

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