module.exports = class Mod {
constructor({ io }) {
this.io = io;
}
run() {
this.io.something();
}
}
var express = require('express')
, app = express()
, path = require('path')
, server = require('http').createServer(app)
, io = require('socket.io')(server)
, Mod = require("./mod")
const mod = new Mod({ io });
mod.run();
server.listen(8080);
app.use(express.static(path.join(__dirname, 'public'));
const { promisify } = require('util');
/* ... */
const query = promisify(connection.query).bind(connection);
const commit = promisify(connection.commit).bind(connection);
const rollback = promisify(connection.rollback).bind(connection);
const beginTransaction = promisify(connection.beginTransaction).bind(connection);
/* ... */
async function run(title) {
try {
await beginTransaction();
const { insertId } = await query('INSERT INTO posts SET title=?', title);
const log = `Post ${insertId} added`;
await query('INSERT INTO log SET data=?', log);
await commit();
console.log('Success!');
} catch (e) {
await rollback();
}
}
const fetch = require('node-fetch');
const SocksProxyAgent = require('socks-proxy-agent');
const { URL } = require('url');
const proxy = process.env.socks_proxy || 'socks://127.0.0.1:9050';
const endpoint = process.argv[2] || 'http://nodejs.org/api/';
console.log('using proxy server', proxy);
console.log('attempting to GET', endpoint);
const agent = new SocksProxyAgent(proxy);
fetch(endpoint, { agent })
.then(response => response.text())
.then((text) => {
console.log('Response:', text);
})
.catch(console.error);
{
answear(ids) {
return new Promise((resolve, reject) => {
const bindings = ids.map(id => '?').join(',');
db.query(
`SELECT * FROM answers WHERE id_question IN (${bindings})`,
ids,
(error, rows) => {
if (error) {
return reject(error);
}
resolve(rows);
}
);
});
}
}
.on('response', (response) => {
let body = '';
response.on('data', (chunk) => {
body += String(chunk);
});
response.on('end', () => {
body = JSON.parse(body);
console.log(body);
});
})
const { VK } = new require('vk-io');
const vk = new VK();
vk.setOptions({...});
vk.upload.document({
group_id: 1234,
source: __dirname + '/file.gif'
})
.then((doc) => {
console.log('Success upload', doc);
/* ...code */
})
.catch(console.error);