Build an IoT dashboard with JavaScript and PubNub
Build an IoT dashboard with the PubNub JavaScript SDK: wildcard subscribe to device channels, online status with Presence, commands and firmware files.
Set up your environment
In this tutorial you run an IoT dashboard in the browser and look at how it's built with the PubNub JavaScript SDK. The devices are simulated: each one runs in a web worker in the same page, but it talks to the dashboard only over PubNub, the way a real device would. You see each device on a map with its latest reading and online status, and you can rename it, change how often it reports, reboot it and send it a firmware file.
You need:
Node.js with npm. The app uses a small Express server to serve the page.
A code editor, for example Visual Studio Code
A current browser: Chrome, Firefox, Safari or Edge
A Google Maps API key for the map. You create one in the build steps.
Get the code
Clone the repository and install the dependencies:
git clone https://github.com/PubNubDevelopers/iot-dashboard-javascript-demo.git
cd iot-dashboard-javascript-demo
npm installTested with the PubNub JavaScript SDK 13.1.2 and Node.js 22, at commit 1d93f1b of the repository (October 2026).
Create keys
You need a free PubNub account and a keyset with Presence and File Sharing on. Create it with your AI coding tool and the PubNub MCP Server, or with the Admin API. Leave Access Manager off, as it is on a new keyset: the build steps explain why.
With the PubNub MCP Server
The PubNub MCP Server lets your AI tool create apps and keysets in your account. It runs at https://mcp.pubnub.com and you sign in with your PubNub account, so there's nothing to install. MCP connections must be allowed for your organization; an Account Owner or Account Admin controls this in organization settings.
Create a free account if you don't have one, then add the server to your tool:
- Claude Code: run
claude mcp add --scope user --transport http pubnub https://mcp.pubnub.com, startclaude, enter/mcp, select pubnub, then authenticate, and sign in. - Cursor: add
{"mcpServers": {"PubNub": {"url": "https://mcp.pubnub.com"}}}to.cursor/mcp.json, click Enable in the notification, and sign in when prompted. Use the agent in Agent mode. - VS Code: add
{"servers": {"PubNub": {"type": "http", "url": "https://mcp.pubnub.com"}}}to.vscode/mcp.jsonand sign in when prompted. - Claude Desktop, Codex, Gemini CLI, and OpenCode: see Set up the MCP server.
When you sign in, select your organization and click Allow access. Then ask your tool: "Create a PubNub app with a testing keyset for an IoT dashboard tutorial. Enable Presence and File Sharing, leave Access Manager off, then show me the publish and subscribe keys." Copy both keys. You'll paste them into public/js/keys.js later in the build steps.
With the Admin API
To create keys from a script or a CI/CD pipeline, use the Admin API, PubNub's REST API for account management. An Account Owner or Account Admin creates a Service Integration and its API key in the Admin Portal under Organization Settings → API Management. Give it read & write access to apps and keysets, plus read access to secret keys, which keyset creation requires. With that key, create an app, then create a testing keyset in it and pass the keyset's configuration in the same request. The response includes the publish and subscribe keys. See the Admin API documentation for the requests and keyset settings.
Check Presence
However you create the keyset, open it in the Admin Portal and make sure Presence tracks All channels. The recommended setting, Selected channels only, doesn't generate presence events until you add a rule in Presence Management. Sensor readings would still arrive, but the dashboard wouldn't see devices go offline, even after a reboot. All channels is fine for a test keyset with a few users, but the portal warns that it can get expensive on a busy keyset. On a production keyset, keep Selected channels only and add a rule for device.* with the join, leave, and timeout events.
The dashboard also needs Stream Controller for its wildcard subscribe to device.*. Stream Controller is on by default for new keysets; keep it on and make sure Wildcard Subscribe is enabled in its settings.
Build and run
Congratulations - what's next?
You have an IoT dashboard on the PubNub JavaScript SDK: one channel per device, a wildcard subscription to all of them, online status from Presence, commands as messages and firmware files with File Sharing.
To take it further:
Keep devices on the server. The devices only live in the page. To share them between dashboards, store each device's details with DataSync (it needs Access Manager) or in your own database.
React to readings on PubNub. A Function can check every reading as it's published, for example to alert someone when a freezer gets too warm.
Connect real devices. A device needs the same three things as the simulator: its own channel, a User ID and your keys. Use a PubNub SDK for your device's platform.
Go further with the JavaScript SDK
JavaScript SDK documentation Presence File Sharing IoT dashboard demoBefore you go to production
Control who can publish. With Access Manager off, anyone with your keys can publish on any device channel, including commands. Turn on Access Manager, and have your own server give each device a token for its own channel only and the dashboard a token for
device.*. That server replacesrequestAccessManagerToken()and the demo token server.Treat readings as untrusted. The dashboard writes device names and readings into the page with
innerHTML. Set them withtextContentinstead, and check that each reading has the fields and types you expect before you use it.Filter the dashboard's own commands with
meta, as described in the build steps, if you don't want them delivered back.
Ready to get beyond proof of concept?
Schedule a 15-minute chat with one of our experts to get your project moving.
Talk to an ExpertTake it to production on your own keys
Create a free PubNub account to get permanent keys for this app.