ADD: redis client and connection

This commit is contained in:
MohammadHMazarei
2024-12-24 19:26:44 +03:30
parent 6dcd9b976e
commit a7d7df8bf4
+7 -2
View File
@@ -1,4 +1,5 @@
const mongoose = require('mongoose') const mongoose = require('mongoose')
const redisClient = require('./redis')
const port = process.env.PORT || 3000 const port = process.env.PORT || 3000
const env = process.env.NODE_ENV || 'development' const env = process.env.NODE_ENV || 'development'
module.exports = (app) => { module.exports = (app) => {
@@ -14,15 +15,19 @@ module.exports = (app) => {
.connect(connectionString, {}) .connect(connectionString, {})
.then(async function () { .then(async function () {
console.log('MongoDB Database Connected') console.log('MongoDB Database Connected')
const MyModel = mongoose.model('MyCollection', new mongoose.Schema({name: String})); const MyModel = mongoose.model('MyCollection', new mongoose.Schema({ name: String }))
// Create a document to force MongoDB to actually create the DB and collection // Create a document to force MongoDB to actually create the DB and collection
await MyModel.create({name: 'test'}); await MyModel.create({ name: 'test' })
redisClient.connect().then((r) => {
console.log('Redis connection Established')
app.listen(port, function () { app.listen(port, function () {
console.log('Server Started On Port ' + port) console.log('Server Started On Port ' + port)
}) })
}) })
})
.catch(function (err) { .catch(function (err) {
console.log(err) console.log(err)
}) })