temp.html works if execute.js removed and csv file present
sudo node copyfile works from command line
Code: Select all
--------------------------------------------------------------
Temp.html
<html>
<head>
<script type="text/javascript"
src="dygraph.js"></script>
<link rel="stylesheet" src="dygraph.css" />
</head>
<body>
<div id="graphdiv2"
style="width:1200px; height:700px;"></div>
<script src="require.js"></script>
<script src="execute.js"></script>
<script type="text/javascript">
g2 = new Dygraph(
document.getElementById("graphdiv2"),
"tempdata2.csv", // path to CSV file
{
// customBars: true,
// title: 'Central Heating Data - xx/xx/xx',
ylabel: 'Temperature (C)',
legend: 'always',
showRangeSelector: true,
rollPeriod: 1
// showRoller: true
} // options
);
</script>
</body>
</html>
--------------------------------------------------------------
Execute.js (run copyfile with sudo)
//define(function (require) {
// var namedModule = require('child_process');
//});
function execute(command) {
const exec = require(['child_process']).exec
exec(command, (err, stdout, stderr) => {
process.stdout.write(stdout)
})
}
execute('sudo node copyfile')
--------------------------------------------------------------
copyfile.js
//copyfile.js
const fs = require('fs');
// destination will be created or overwritten by default.
fs.copyFile('/media/usb/tempdata2.csv', '/var/www/html/tempdata2.csv', (err) =>$
if (err) throw err;
console.log('File was copied to destination');
});
--------------------------------------------------------------