
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
@node-wot/binding-file
Advanced tools
In the following examples it is shown how to use the File binding of node-wot.
npm install @node-wot/core
npm install @node-wot/binding-file
test.txt
with contentThe example tries to load an internal TestThing TD and reads a property fileContent
which exposes the content of the file test.txt
.
node example1.js
// example.js1
Servient = require("@node-wot/core").Servient
FileClientFactory = require("@node-wot/binding-file").FileClientFactory
// create Servient and add File binding
let servient = new Servient();
servient.addClientFactory(new FileClientFactory(null));
td = {
"id": "urn:dev:wot:org:w3:testthing:file",
"title": "TestThing",
"@context": "https://www.w3.org/2019/wot/td/v1",
"@type": "Thing",
"security": ["nosec_sc"],
"properties": {
"fileContent": {
"type": "string",
"readOnly": true,
"observable": false,
"forms": [{
"href": "file://test.txt",
"contentType": "text/plain",
"op": ["readproperty"]
}]
}
},
"securityDefinitions": {
"nosec_sc": {
"scheme": "nosec"
}
}
};
// try to read property that exposes the content of file test.txt
try {
servient.start().then((WoT) => {
WoT.consume(td).then((thing) => {
// read property "fileContent" and print the content
thing.readProperty("fileContent").then((s) => {
console.log("Content of File:\n" + s);
});
});
});
} catch (err) {
console.error("Script error:", err);
}
The example tries to load a locally stored TestThing TD and reads a property fileContent
which exposes the content of the file test.txt
.
TD.jsonld
with content as in Example 1node example2.js
// example2.js
Servient = require("@node-wot/core").Servient
FileClientFactory = require("@node-wot/binding-file").FileClientFactory
Helpers = require("@node-wot/core").Helpers
// create Servient and add File binding
let servient = new Servient();
servient.addClientFactory(new FileClientFactory(null));
let wotHelper = new Helpers(servient);
wotHelper.fetch("file://TD.jsonld").then(async (td) => {
// using await for serial execution (note 'async' in then() of fetch())
try {
servient.start().then((WoT) => {
WoT.consume(td).then((thing) => {
// read property "fileContent" and print the content
thing.readProperty("fileContent").then((s) => {
console.log("Content of File:\n" + s);
});
});
});
} catch (err) {
console.error("Script error:", err);
}
}).catch((err) => { console.error("Fetch error:", err); });
FAQs
File client protocol binding for node-wot
The npm package @node-wot/binding-file receives a total of 15 weekly downloads. As such, @node-wot/binding-file popularity was classified as not popular.
We found that @node-wot/binding-file demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.