Node
Node allows to run javascript without a browser. It could be useful for some none graphical functionality such as the DICOM parsing. To install dwv and its dependencies, run:
npm install dwv
Once installed you can create a main.js
file such as:
var dwv = require("dwv");
var fs = require("fs");
// read DICOM file
var data = fs.readFileSync("dwv-test-simple.dcm");
// convert data to array buffer
var arrayBuffer = new Uint8Array(data).buffer;
// parse
var dicomParser = new DicomParser();
dicomParser.parse(arrayBuffer);
// wrapped tags
var tags = dicomParser.getDicomElements();
// log
console.log(tags["00100010"].value[0]);
To execute it, run:
node main.js
You can create a test package by running npm pack
in a folder containing a package.json
file. Install it by running npm install my-package.tgz
.
Note: I've not tested all the classes of dwv in node, it is possible some of them use browser provided methods that node does not have. For example App uses the HTML 'canvas' which can be added by installing a 'node-canvas' (see help from Konva). Konva is disabled in the module intro.js
file. Another one could be the 'XMLHttpRequest'...
Links:
For development purposes, you can create your own npm package by calling npm pack
in the root folder. You can then install it in your project folder using npm install dwv-#.tgz
.
AMD
AMD is an Asynchronous Module Definition, modules are loaded only when they are needed. The requirejs library defines the function needed to use AMD (see its API). This repo gives a good example. Dwv can be 'required' by using its file name or directly if it is in the config baseUrl
:
var dwv = require("dwv");