File tree Expand file tree Collapse file tree 3 files changed +15
-11
lines changed Expand file tree Collapse file tree 3 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,11 @@ import {
9
9
export const PollModel = model < PollDocument > ( 'Poll' , pollSchema )
10
10
export const StudentModel = model < StudentDocument > ( 'Student' , studentSchema )
11
11
12
- connect ( process . env . MONGODB_URL ) . catch ( ( err ) => {
13
- throw err
14
- } )
12
+ export async function connectMongo ( ) {
13
+ await connect ( process . env . MONGODB_URL )
14
+ db . on ( 'open' , ( ) => {
15
+ console . log ( 'Connected to mongo' )
16
+ } )
17
+ }
15
18
16
19
export const db = connection
Original file line number Diff line number Diff line change @@ -2,11 +2,12 @@ import { createClient } from 'redis'
2
2
import fs from 'fs'
3
3
import path from 'path'
4
4
import readline from 'readline'
5
+
5
6
const client = createClient ( {
6
7
url : process . env . REDIS_URL
7
- } ) ;
8
+ } )
8
9
9
- ( async ( ) => {
10
+ async function connectRedis ( ) {
10
11
client . on ( 'error' , ( err ) => console . log ( 'Redis Client Error' , err ) )
11
12
12
13
await client . connect ( )
@@ -25,6 +26,6 @@ const client = createClient({
25
26
console . log ( line . trim ( ) )
26
27
client . set ( line . trim ( ) , 'instructor' )
27
28
}
28
- } ) ( )
29
+ }
29
30
30
- export { client }
31
+ export { client , connectRedis }
Original file line number Diff line number Diff line change @@ -6,13 +6,11 @@ import cors from 'cors'
6
6
import cookieParser from 'cookie-parser'
7
7
import { io } from './socket'
8
8
import pollRouter from './routes/pollRoute'
9
- import { db } from './db/mogoose'
9
+ import { connectMongo } from './db/mogoose'
10
10
import userRouter from './routes/userRoutes'
11
11
import { getUser } from './controllers/userController'
12
+ import { connectRedis } from './redis'
12
13
dotenv . config ( )
13
- db . on ( 'open' , ( ) => {
14
- console . log ( 'Connected to mongo' )
15
- } )
16
14
17
15
// starting the express server
18
16
const app = express ( )
@@ -46,6 +44,8 @@ app.use('/poll', pollRouter)
46
44
47
45
const server = app . listen ( port , ( ) => {
48
46
console . log ( 'Listening on http://localhost:' + port )
47
+ connectRedis ( )
48
+ connectMongo ( )
49
49
io . attach ( server )
50
50
io . use ( async ( socket , next ) => {
51
51
try {
You can’t perform that action at this time.
0 commit comments