var child = require('child_process').execFile;
var executablePath = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
child(executablePath, function(err, data) {
if(err){
console.error(err);
return;
}
console.log(data.toString());
});
socket.emit('getUserInfo')
io = require('socket.io').listen(httpsServer);
io.on('connection', function(socket) {
socket.on('getUserInfo', function(e) {
//code
...
socket.emit('sendUserInfo', data)
})
});
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var mkdirp = require('mkdirp');
var appPort = process.env.APPPORT || "5000"
app.set('views', __dirname + '/app/views')
app.set('view engine', 'pug')
app.use(express.static(__dirname + '/public'))
server.listen(appPort, function () {
console.log('Server listening at port %d', appPort);
});
//App components
var routes = require('./app/routes');
app.use('/', routes);
io.attach(server);
var socket = require('./app/socket');
socket.start(io);
npm install -g @angular/cli
npm i --save supervisor
"scripts": {
"test": "node_modules\\\\.bin\\\\supervisor index.js",
"start": "node index.js"
},
npm test
var getDataFromDatabase = function () {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if(err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return callback(null, arr);
})
.on('error', function(err){
return callback (err, null);
});
}
module.exports = {
getDataFromDatabase
}
var fromDB = require(./modulName);
fromDB.getDataFromDatabase(function(err, result){
if(err){
console.log(err);
} else {
console.log(result);
}
})
var getDataFromDatabase = function (callback) {
return new Promise((resolve, reject) => {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if (err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return resolve(arr);
})
.on('error', function (err) {
return reject(err);
})
});
})
}
module.exports = {
getDataFromDatabase
}
var fromDB = require("./modulName");
fromDB.getDataFromDatabase()
.then(result =>{
console.log(result);
},(err)=>{
console.log(err);
})
var getDataFromDatabase = async function (callback) {
return new Promise((resolve, reject) => {
var arr = []
var con = mysql.createConnection(conf.config);
con.connect(function (err) {
if (err) throw err;
con.query("SELECT DID, DName FROM Device")
.on('result', function (data) {
arr.push(data)
})
.on('end', function () {
return callback(null, arr);
})
.on('error', function (err) {
return callback(err, null);
})
});
})
}
module.exports = {
getDataFromDatabase
}
var fromDB = require("./modulName");
var test = await fromDB.getDataFromDatabase();
var winston = require('winston');
//logger is configured to save output to log file
var logger = new (winston.Logger)({
level: level,
transports: [
new (winston.transports.File)({
filename: '' + logdir + "/" + timeAct + '_' + program.server + '.log',
json: false
})
]
});
//add console output if debug is on
if (program.debug) {
logger.add(winston.transports.Console, { json: false });
} else {
if (program.debugfile) {
logger = new (winston.Logger)({
level: 'debug',
transports: [
new (winston.transports.File)({
filename: '' + logdir + "/" + timeAct + "_" + program.server + '_debug_.log',
json: false
})
]
});
} else {
//if error, write to console
logger.add(winston.transports.Console, {
level: 'error',
json: false
});
}
}