Research Article

HealthNode: Software Framework for Efficiently Designing and Developing Cloud-Based Healthcare Applications

Listing 4

Calling child submodule function, controlling external development board using serial communication, and managing file exchange.
(1)//Execute external program or classifier
(2)var querystring = require(“child_process”).executable;
  ...
(4)app.post(‘/method’, function(req, res){
(5) executable(“./execProgram “ + ”testFile”, function(err, stdout, stderr){
(6)  //output is on stdout
(7)}
(8)});
  ...
(10)//For serialport
(11)var SerialPort = require(‘serialport’);
(12)var Readline = SerialPort.parsers.Readline;
(13)var port = new SerialPort(‘/dev/ttyUSB0’,{baudrate: 9600 });
(14)var parser = port.pipe(Readline({delimiter: ‘\r\n’}));
(15)//Getting data from external board
(16)parser.on(‘data’, function(data){
(17)   console.log(data);
(18)});
(19)//Sending data to external board
(20)port.write(‘some data’);
  ...
(26)//File upload/download
(27)var fs = require(“fs”);
  ...
(30)//File upload:
(31)app.post(‘/uploads’, function(req, res) {
(32) fs.readFile(req.files.fileU.path, function(err,data){
(33)  var dirname = “/file/dir/location”;
(34)  var newPath = dirname + “/uploads/” + req.files.fileU.originalname;
(35)  fs.writeFile(newPath, data, function (err){
  ...
(41)//Access file on server:
(42)app.get(‘/uploads/:file’, function(req, res){
(43)  file = req.params.file;
(44)  console.log(“File requested: ” + file);
(45)  var dirname = “/file/dir/location”;
(46)  var img = fs.readFileSync(dirname + “/uploads/”+file);
(47)  res.writeHead(200, {‘Content-Type’: ‘image/jpg’});
(48)  res.end(img, ‘binary’);
(49)});