var http = require('http'),
exec = require('child_process').exec,
fs = require('fs') ;
function onRequest(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
fs.readFile('form.html', function(err, data){
if(err)
{
res.write("err.message");
}
else
{
res.write(data);
res.end();
}
});
}
var server = http.createServer(onRequest);
server.listen(80, '0.0.0.0');
console.log("Server Running");My goal is to display a website which gives users a menu, then from there they click on what functionality they want to run, and then node runs a command on the back end on a ubuntu server using "exec" then displaying the results to the webpage. So far I have two files, a nodejs file and an html page then the form.html My question is, is this the right way of carrying out this task? and if so,should I export the onRequest function which would then allow me to display what I want to the webpage with res.write ? |