If you need a fully functional OPCUA server that exposes a File Node from which you can actually read and write, you can achieve this easily using node-opcua and the following script:
import {
OPCUAServer,
UAFileType,
StatusCodes,
Variant,
CallMethodResultOptions,
SessionContext,
} from "node-opcua";
import { installFileType, getFileData } from "node-opcua-file-transfer";
import { callbackify } from "util";
import * as fs from "fs";
const my_data_filename = "/tmp/someFile.txt";
fs.writeFileSync(my_data_filename, "some content", "utf8");
(async () => {
try {
const server = new OPCUAServer({
port: 26540,
});
await server.initialize();
// now add a file object in the address Space
const addressSpace = server.engine.addressSpace;
const namespace = addressSpace.getOwnNamespace();
// retrieve the FileType UAObjectType
const fileType = addressSpace.findObjectType("FileType")!;
// create a instance of FileType
const opcuaFile = fileType.instantiate({
nodeId: "s=MyFile",
browseName: "MyFile",
organizedBy: addressSpace.rootFolder.objects,
}) as UAFileType;
// now bind the opcuaFile object with our file
installFileType(opcuaFile, {
filename: my_data_filename,
});
await server.start();
console.log("Server is now listening on port 26540.. ( press CTRL+C to stop)");
} catch (err) {
console.log("err", err);
}
})();
More examples can be found in https://leanpub.com/node-opcuabyexample