You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aruppi-api/src/database/connection.ts

43 lines
961 B
TypeScript

import mongoose from 'mongoose';
import redis, { RedisClient } from 'redis';
/*
Create the connection to the database
of mongodb.
*/
export const createConnectionMongo = (databaseObj: {
port: string | undefined;
host: string | undefined;
}) => {
mongoose.connect(
`mongodb://${databaseObj.host}:${databaseObj.port}/anime-directory`,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
);
mongoose.connection.on('error', err => {
console.log('err', err);
});
mongoose.connection.on('connected', (err, res) => {
console.log('Database connected: mongoose.');
});
};
/*
Create the connection to the cache of
redis, and exporting the redis client
with the call of this file.
*/
export const redisClient: RedisClient = redis.createClient({
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT!),
});
redisClient.on('connect', () => {
console.log('Redis connected: redis.');
});