Getting Started
Prerequisites
Scaffold from Template
The fastest way to start is with the official scaffolding command:
pnpm create @bonsae/nrg my-node-red-nodes
cd my-node-red-nodesThen start the dev server:
pnpm vite devOpen the URL printed by Vite in the terminal and you'll see your custom node in the Node-RED palette.
Manual Setup
If you prefer to add NRG to an existing project:
1. Install dependencies
pnpm add @bonsae/nrg @sinclair/typebox vue
pnpm add -D vite2. Configure Vite
Create a vite.config.ts at the project root:
import { defineConfig } from "vite";
import { nodeRed } from "@bonsae/nrg/vite";
export default defineConfig({
plugins: [nodeRed()],
});3. Configure TypeScript
Create tsconfig.json files that extend the shared configs:
tsconfig.json (root)
{
"extends": "@bonsae/nrg/tsconfig/base.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["vite.config.ts"]
}src/server/tsconfig.json
{
"extends": "@bonsae/nrg/tsconfig/server.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["**/*.ts"]
}src/client/tsconfig.json (only needed if you add custom client files)
{
"extends": "@bonsae/nrg/tsconfig/client.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["**/*.ts", "**/*.vue"]
}TIP
The src/client/ directory and its tsconfig.json are optional. NRG auto-generates the client-side code from your server schemas. You only need these if you want to customize the editor behavior or provide custom Vue form components. See Creating a Node for details.
4. Create the entry files
Create the server and client entry points. See the Project Structure page for the full layout, and Creating a Node for a complete walkthrough.
src/server/index.ts
import MyNode from "./nodes/my-node";
export default {
nodes: [MyNode],
};src/client/index.ts
import { registerTypes } from "@bonsae/nrg/client";
import myNode from "./nodes/my-node";
await registerTypes([myNode]);5. Start developing
pnpm vite devThis launches a local Node-RED instance with your nodes pre-installed. Changes to server or client code trigger automatic rebuilds and restarts.