
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
@node-wot/binding-firestore
Advanced tools
Firestore Binding is an implementation of the W3C Web of Things Binding using Firestore, which can be used with Eclipse Thingweb node-wot to embody the Web of Things.
Firestore has the ability to subscribe to written data, and Firestore Binding uses this to perform communication between the Thing and the Client. This Binding provides a storage location (Reference) in Firestore for data corresponding to a Thing's properties, actions, and events. By writing data to the Reference, communication between the Thing or Client that subscribes to the data is realized.
In addition, when you do an Expose thing in a Server program that uses this Binding, the exposed Thing Description will be saved in Firestore. This Thing Description can be accessed by the Client as follows.
wotHelper.fetch("firestore://sample-host/MyCounter").then((td) => {
// do something
}
For more information on how to use Firestore, see How to use Firestore
.
The protocol prefix handled by this binding is firestore://
.
In the following examples, how to use the Firestore binding of node-wot is shown.
You must have a Firebase account to use this binding.
In order to use Firestore Binding, you need to set up Firebase. Perform the following setup from the Firestore console.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
Project Settings
from the top left gear and confirm the Project ID (B) and Web Api Key (C).The values defined in (A), (B) and (C) will be written in the configuration file shown in Configuration
chapter.
To prepare for creating a nodejs app, execute npm install
.
After executing npm init
, install the following modules.
npm install @node-wot/core
npm install @node-wot/binding-firestore
These examples require a configuration file that contains Firestore connection information and other information. This configuration file should contain the following information((A), (B), and (C) correspond to the information written in the Setting up Firebase
chapter):
{
"hostName": "<Host Name defined by user>",
"firebaseConfig": {
"apiKey": "<API Key of Firebase (C)>",
"projectId": "<Project Id of Firebase (B)>",
"authDomain": "<Auth Domain of Firebase(Usually it will be <B>.firebaseapp.com>"
},
"user": {
"email": "<email address registered in Firebase (A)>",
"password": "<password corresponding to the email address above (A)>"
}
}
The information needed to create the configuration file can be found at Firestore console.
The client example tries to connect to MyCounter
thing via Firestore and read the count
property .
The Thing Description is stored in Firebase which can be access by client as firestore://sample-host/MyCounter
.
The Thing Description is registered by example-server.js
.
node example-client.js
// example-client.js
const Servient = require("@node-wot/core").Servient;
const FirestoreClientFactory = require("@node-wot/binding-firestore").FirestoreClientFactory;
const Helpers = require("@node-wot/core").Helpers;
const FirestoreCodec = require("@node-wot/binding-firestore").FirestoreCodec;
const firestoreConfig = require("./firestore-config.json");
let servient = new Servient();
const clientFactory = new FirestoreClientFactory(firestoreConfig);
servient.addClientFactory(clientFactory);
const codec = new FirestoreCodec();
servient.addMediaType(codec);
let wotHelper = new Helpers(servient);
wotHelper
.fetch("firestore://sample-host/MyCounter")
.then(async (td) => {
try {
servient.start().then((WoT) => {
WoT.consume(td).then((thing) => {
// read a property "count" and print the value
thing.readProperty("count").then((s) => {
console.log(s);
});
});
});
} catch (err) {
console.error("Script error:", err);
}
})
.catch((err) => {
console.error("Fetch error:", err);
});
The server example produces a thing that allows for setting a property count
. The thing is reachable via Firestore.
node example-server.js
// example-server.js
const Servient = require("@node-wot/core").Servient;
const FirestoreServer = require("@node-wot/binding-firestore").FirestoreServer;
const FirestoreCodec = require("@node-wot/binding-firestore").FirestoreCodec;
const firestoreConfig = require("./firestore-config.json");
// create server
const server = new FirestoreServer(firestoreConfig);
// create Servient add Firebase binding
let servient = new Servient();
servient.addServer(server);
const codec = new FirestoreCodec();
servient.addMediaType(codec);
let count = 0;
servient.start().then((WoT) => {
WoT.produce({
"@context": "https://www.w3.org/2019/wot/td/v1",
title: "MyCounter",
properties: {
count: {
type: "integer",
observable: true,
readOnly: false,
},
},
}).then((thing) => {
console.log("Produced " + thing.getThingDescription().title);
thing.expose().then(() => {
console.info(thing.getThingDescription().title + " ready");
console.info("TD : " + JSON.stringify(thing.getThingDescription()));
thing.setPropertyReadHandler("count", async () => count);
});
});
});
We will store another example in the packages/examples/src/bindings/firestore/
folder, so please refer to that as well.
This Binding realizes the interaction between Client and Server for Property, Action, and Event by storing data in the following reference.
Data will always be overwritten and no history will be retained.
The WoT operations that can be implemented for Client as follows.
WoT operations | Client |
---|---|
readProperty | ✓ |
readAllProperties | - |
readMultipleProperties | - |
writeProperty | ✓ |
writeMultipleProperties | - |
observeProperty | ✓ |
unobserveProperty | ✓ |
invokeAction | ✓ |
emitEvent | N/A |
subscribeEvent | ✓ |
unsubscribeEvent | ✓ |
Because communication with Firestore occurs, you may be charged for using Firebase. In order to avoid unexpected charges, please check your usage. You can check it at Firebase console.
FAQs
Firestore binding for node-wot
We found that @node-wot/binding-firestore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.