socket.on('connect', function () {
socket.emit('join', {email: user@example.com});
});
io.on('connection', function (socket) {
socket.on('join', function (data) {
socket.join(data.email);
});
});
io.to('user@example.com').emit('message', {msg: 'hello world.'});
socket.on("message", function(data) {
alert(data.msg);
});
При таком подходе, пропадает необходимость использовать app.get(), так как все файлы и так будут отданы. Плюс, смущает факт того, что доступ к файлам можно получить прописав путь напрямую /home/index.html
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();
backupRun.prototype.checkSSHConnection = async function (serverName) {
var self = this;
var exec = self.bConfig.clientserver[self.eServer]
var client = self.bConfig.clientserver[serverName]
return new Promise((resolve, reject) => {
self.runUnderSSH("hostname", self.sshkey, exec, client)
.then((sshOutput) => {
return resolve(sshOutput);
}, (sshOutputErr) => {
return reject(sshOutputErr)
})
})
};
backupJob.checkSSHConnection(program.exec) //check ssh to exec server
.then((response) => {
logger.debug("SSH test connection to exec " + program.exec + " successfull");
backupJob.checkSSHConnection(program.server) //check ssh connection to backup server
.then((response) => {
logger.debug("SSH test connection to backup server " + program.exec + " successfull");
backupJob.createBackupPrePostCommands('prerun') //create backup server prerun commands
.then((backupPreRun) => {
logger.debug("Create backup prerun commands");
}, (err) => {
logger.error("Error: config array was not generated " + err);
})
})
})
}, (error) => {
logger.error("SSH test connection to backup server " + program.exec + " failed: " + error);
})
}, (error) => {
logger.error("SSH test connection to exec " + program.exec + " failed: " + error);
});