clientData.connect().then((client) => { clientData.on('notification', function(msg) { console.log(msg); }); clientData.query('LISTEN watchers'); }).catch((err) => { console.log(err); });
async _createClient() { const client = new Client(this.options.connectionConfig); client.lock = new AwaitLock(); client.on('error', (error) => { this.emit('error', error, client); }); client.on('end', () => { this.emit('disconnect', client); }); await client.connect(); this.emit('connect', client); return client; }
pgClient.on('notification', function(data) { console.log('_____________________'); console.log('Change notification'); io.emit("change"); });
listen() { let {client, config: {connection, channels}} = this; channels = Array.isArray(channels) ? channels : []; if (channels.length === 0) { throw new Error(msg.NO_CHANNELS_TO_LISTEN); } client.connect(err => { if (err instanceof Error) { halt(err); } logger.info(msg.DATABASE_CONNECTED, yellow(connection.database)); }); client.on('notice', msg => logger.info(msg)); client.on('notification', notification => this.handle(notification)); channels.forEach(channel => this.listenTo(channel)); }