Skip to content

Commit

Permalink
removed logging db
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheetal Godara authored and Sheetal Godara committed Oct 24, 2023
1 parent e7a9d8e commit 91ddb1a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
19 changes: 1 addition & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@ const app = express();
const winston = require('winston');

require('./startup/config')();
const logger = require('./startup/logging');

if(app.get('env')=== 'production'){
require('./startup/prod')(app);
app.use((req, res, next) => {
const start = Date.now();
res.on('finish', () => {
const responseTime = Date.now() - start;
const userAgent = req.headers['user-agent'] || 'Unknown';
const authToken = req.headers['x-auth-token'] || 'N/A';//maybe avoid and do this for erroror to seelog of unwanted request whomaking
logger.info(`${req.ip} - ${userAgent} - Auth Token: ${authToken} - ${req.method} ${req.originalUrl} - ${res.statusCode} - ${responseTime}ms`);
//logger.info(`${req.ip} - ${req.method} ${req.originalUrl} - ${res.statusCode} - ${responseTime}ms`);
});
next();
});
}


process.on('unhandledRejections',(ex) =>{
//console.log(ex)
Expand Down Expand Up @@ -52,5 +35,5 @@ app.use(function(req,res,next){
*/

const port = process.env.PORT||3000
const server = app.listen(port,()=>logger.info(`listening to port ${port}...`));
const server = app.listen(port,()=>console.log(`listening to port ${port}...`));
module.exports = server
3 changes: 1 addition & 2 deletions startup/db.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const mongoose = require('mongoose');
const winston = require('winston');
const config = require('config');
const logger = require('./logging');

module.exports = function(){
mongoose.set('strictQuery', false);//to check right choice
const db = config.get('db')+"?retryWrites=true&w=majority";
mongoose.connect(db,{family: 4,useUnifiedTopology:true})
.then(()=>logger.info(`Connected to Mongodb...${db}`))//
.then(()=>console.log(`Connected to Mongodb...${db}`))//
// .catch(err => dbDebugger('couldnot connect to mongodb',err))//as not logging enough need to terminate so done seperately
}

Expand Down

0 comments on commit 91ddb1a

Please sign in to comment.