Contribute to this page
Quickstart
This quickstart takes you from nothing to a working MACHHUB app in a few minutes. You will connect to a running MACHHUB Platform, create a Collection, write a record, and subscribe to a live Tag.
1. Create a collection in the console
Section titled “1. Create a collection in the console”The fastest way to model data is the web console:
- Open the console and sign in.
- Go to Database → Collections and click Add Collection.
- Name it
products, then add fields — for examplename(String),sku(String),price(Number), andinStock(Boolean). Anidfield is always created for you. - Save. You now have a
productscollection you can read and write from the SDK.
See Build a Collection for the full walkthrough, or Collection JSON to import a schema as JSON.
2. Install the SDK
Section titled “2. Install the SDK”npm install @machhub-dev/sdk-ts3. Initialize the SDK
Section titled “3. Initialize the SDK”import { SDK } from '@machhub-dev/sdk-ts';
const sdk = new SDK();
// Recommended (dev and prod): no connection config. In development the MACHHUB// Designer proxies your dev server's SDK requests to the connected platform; in// production the app is hosted on MACHHUB, so the SDK resolves its connection.await sdk.Initialize();
// Manual config — only when you self-host the app, target a different server/domain,// or want to hardcode the connection:// await sdk.Initialize({// application_id: 'myapp',// httpUrl: 'http://localhost:80',// mqttUrl: 'mqtt://localhost:1883',// });4. Create and read records
Section titled “4. Create and read records”// Create a productawait sdk.collection('products').create({ name: 'Wireless Mouse', sku: 'MOUSE-001', price: 29.99, inStock: true,});
// Query: in-stock products under $50, newest firstconst cheap = await sdk .collection('products') .filter('inStock', '=', true) .filter('price', '<', 50) .sort('price', 'asc') .getAll();
console.log(cheap);Record IDs use the form application_id.collection:record_id, e.g.
myapp.products:PROD-001. See SDK → Collections for queries,
relations, pagination, and the full CRUD surface.
5. Subscribe to a live tag
Section titled “5. Subscribe to a live tag”Tags are live signals in the Unified Namespace, delivered over MQTT.
// Subscribe to a tag and react to every new valueawait sdk.tag.subscribe('line1/oven/temperature', (value) => { console.log('temperature =', value);});
// Publish a value (e.g. from a gateway or a test)await sdk.tag.publish('line1/oven/temperature', 72.4);To store history for a tag, enable historization on it (see Historize a tag), then query it:
const rows = await sdk.historian.query(` SELECT time::floor(time, 1h) AS hour, math::mean(value) AS avg FROM historian WHERE topic = 'line1/oven/temperature' GROUP BY hour ORDER BY hour ASC`);Next steps
Section titled “Next steps”- Structure your app with the service-layer architecture.
- Add auth with SDK → Authentication.
- Pick your framework: Angular, React/Next.js, Vue/Nuxt, or SvelteKit.
- Automate logic with Processes.