Nexo Maker Docs
  • Welcome
  • Getting Started
    • Basic Concepts
      • Starting a Expansion
      • Compiling your Expansion
  • Visual API
    • Modularjs
      • Modularjs Basics
      • Styling
      • useState()
      • useEffect()
      • useGlobalState()
      • useProjectState()
    • [Deprecated] Components
      • Custom HTML documents
    • Themes
      • Replace Assets
      • Assets List
  • Functional API
    • Post Functions
      • Post Sidebar Button
      • Post Editor Module
    • Get Functions
      • Load Assets
      • Load File
      • Get Project
  • API Changelogs
    • Changelog 0.6.1
Powered by GitBook
On this page
  • πŸ“˜ Syntax
  • 🧩 Parameters
  • πŸ“€ Returns
  • βœ… Example: Reading a JSON File
  • βœ… Example: Injecting HTML + CSS into a Component
  • ⚠️ Notes
  • πŸ’‘ Common Use Cases
  1. Functional API
  2. Get Functions

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

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

PreviousLoad AssetsNextGet Project

Last updated 18 days ago