From f808f9690f1fb2f59657d6b66fecbe984fa50d0c Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Mon, 14 Dec 2020 08:49:28 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20connections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/connections/db_conn.js | 19 ------------------- server/connections/influx_conn.js | 19 +++++++++++++++++++ server/connections/redis_conn.js | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) delete mode 100644 server/connections/db_conn.js create mode 100644 server/connections/influx_conn.js create mode 100644 server/connections/redis_conn.js diff --git a/server/connections/db_conn.js b/server/connections/db_conn.js deleted file mode 100644 index a206b0f..0000000 --- a/server/connections/db_conn.js +++ /dev/null @@ -1,19 +0,0 @@ -const {InfluxDB} = require('@influxdata/influxdb-client') -const chalk = require('chalk') - -const {url, token, org, bucket} = require('../config/dev') - -const client = new InfluxDB({ - url: url, - token: token, -}); - -const writeApi = client.getWriteApi( - org, - bucket -); - -const queryApi = client.getQueryApi(org); -console.log(chalk.yellow('Initialized Database connection...')); - -module.exports = {writeApi, queryApi} \ No newline at end of file diff --git a/server/connections/influx_conn.js b/server/connections/influx_conn.js new file mode 100644 index 0000000..9d2dbc9 --- /dev/null +++ b/server/connections/influx_conn.js @@ -0,0 +1,19 @@ +const {InfluxDB} = require('@influxdata/influxdb-client') +const chalk = require('chalk') + +const {influx_url, influx_token, influx_org, influx_bucket} = require('../config/keys') + +const client = new InfluxDB({ + url: influx_url, + token: influx_token, +}); + +const writeApi = client.getWriteApi( + influx_org, + influx_bucket +); + +const queryApi = client.getQueryApi(influx_org); +console.log(chalk.greenBright.bold('Connected to influx!')) + +module.exports = {writeApi, queryApi} \ No newline at end of file diff --git a/server/connections/redis_conn.js b/server/connections/redis_conn.js new file mode 100644 index 0000000..80e3e94 --- /dev/null +++ b/server/connections/redis_conn.js @@ -0,0 +1,14 @@ +const redis = require('redis'); +const chalk = require('chalk'); + +const {redis_user, redis_password, redis_host, redis_port} = require('../config/keys') + +const client = redis.createClient(`redis://${redis_host}:${redis_port}`); + +client.on('error', function (error) { + console.error(error); +}); + +console.log(chalk.greenBright.bold('Connected to redis!')) + +module.exports = {client} \ No newline at end of file