G.js is distributed as an npm package and runs on Node.js. This page walks you through installing the package, choosing an import style, and making sure TypeScript is configured correctly before you write your first line of level code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/g-js-api/G.js/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Node.js — any reasonably modern LTS release (16+) works. G.js uses ES modules (
"type": "module"is recommended for your project). - A supported platform — Windows, macOS, Linux, or Android.
- A package manager: npm, yarn, or pnpm.
Install the Package
@g-js-api/g.js on the npm registry. No build step or bundler is required — you import it directly in your Node.js script.
Project Setup
Create a new JavaScript (or TypeScript) file for your level script. Using the
.mjs extension or setting "type": "module" in your package.json is recommended because G.js is an ES module.This single import registers all G.js functions and constants as global variables. After this line,
trigger_function, unknown_g, group, counter, obj_props, wait, and every other exported name are available anywhere in your file without further destructuring.import {
group,
color,
trigger_function,
counter,
unknown_g,
unknown_c,
unknown_b,
obj_props,
wait,
ignore_context_change,
on, touch,
$
} from '@g-js-api/g.js/safe';
The
/safe entry point exports everything individually and adds nothing to the global scope. Import exactly the names your file uses. See Safe Mode for a deeper guide.$.exportConfig() is an async function that tells G.js how to export the finished level. It must be awaited, and it must run before you create any groups, objects, or triggers.await $.exportConfig({
type: 'savefile', // or 'levelstring', 'live_editor', 'gmd'
options: {
info: true, // print level stats when the script finishes
level_name: 'My Level'
}
});
Placing
$.exportConfig() after any GD content (objects, groups, trigger calls) will produce incorrect or empty output. Always put it at the very top of your level logic, immediately after your imports.import '@g-js-api/g.js';
await $.exportConfig({ type: 'savefile', options: { info: true } });
// your level code goes here
let myGroup = unknown_g();
'Hello, World!'
.to_obj()
.with(obj_props.X, 45)
.with(obj_props.Y, 45)
.with(obj_props.GROUPS, myGroup)
.add();
TypeScript Support
The package ships its own type declarations. The"types" field in package.json points to index.d.ts, which re-exports all types from the safe module. No @types/ package is needed.
For the global import style, the ambient declarations in src/runtime.d.ts describe the globals that are injected when you import '@g-js-api/g.js'. If your editor does not pick these up automatically, add a triple-slash reference or include the file in your tsconfig.json:
tsconfig.json
@g-js-api/g.js:
| Type | Description |
|---|---|
ExportConfig | Argument shape for $.exportConfig() |
ExportOptions | Options object within ExportConfig |
GJsObject | The object returned by object() and .to_obj() |
TriggerFunctionGroup | Return value of trigger_function(), with .call() and .remap() |
Counter | Full counter interface including arithmetic and comparison methods |
FloatCounter | Counter with additional round() and floor() methods |
Context | Low-level context class for advanced trigger-context manipulation |
Export Modes at a Glance
type | What happens |
|---|---|
levelstring | Returns the raw GD levelstring; store it in a variable or print it |
savefile | Writes the level directly into your local GD save file |
live_editor | Streams objects to GD via the WSLiveEditor mod (live preview) |
gmd | Exports a .gmd file compatible with GD World / external editors |