Skip to content
MACHHUB MACHHUB MACHHUB

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.

The fastest way to model data is the web console:

  1. Open the console and sign in.
  2. Go to Database → Collections and click Add Collection.
  3. Name it products, then add fields — for example name (String), sku (String), price (Number), and inStock (Boolean). An id field is always created for you.
  4. Save. You now have a products collection 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.

Terminal window
npm install @machhub-dev/sdk-ts
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',
// });
// Create a product
await sdk.collection('products').create({
name: 'Wireless Mouse',
sku: 'MOUSE-001',
price: 29.99,
inStock: true,
});
// Query: in-stock products under $50, newest first
const 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.

Tags are live signals in the Unified Namespace, delivered over MQTT.

// Subscribe to a tag and react to every new value
await 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
`);