emd-demo-pkg
Version:
EMD Demo
49 lines (36 loc) • 1.38 kB
JavaScript
var lodash = require('lodash');
// Load the http module to create an http server.
var http = require('http');
var exec = require('child_process').exec, child;
var mylib = require( './libs/mylib');
exports.printMsg = function() {
console.log("This is a message from the EMD demo package");
}
exports.executeCmd = function(_cmd) {
// Creamos la función y pasamos el string pwd
// que será nuestro comando a ejecutar
console.log("Ejecutando comando EMD " + _cmd);
child = exec(_cmd,
// Pasamos los parámetros error, stdout la salida
// que mostrara el comando
function (error, stdout, stderr) {
// Imprimimos en pantalla con console.log
console.log(stdout);
// controlamos el error
if (error !== null) {
console.log('exec error: ' + error);
}
});
}
exports.startEMDServer = function(){
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write(mylib.escribir());
response.end("Hi, EMD Server is running...\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
}