title: How to share a object with node + express
body: <p>I´m using Node + express and I´m trying to figure out how to share objects instances in the main js file with my modules. I have this code at bellow.</p>
  
  <pre><code>var express = require('express');
  
  //libs
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var conf      = require('config');
  var logConf   = conf.get('log');
  var winston = require('winston');
  
  
  //modules
  var index = require('./routes/index');
  var users = require('./routes/users');
  var camera = require('./routes/camera');
  var face = require('./routes/face');
  var secret = require('./routes/secret');
  var attendance = require('./routes/attendance');
  var azure = require('./routes/azure-test');
  
  //configuring log
  var logger = new (winston.Logger)({
      transports: [
        new (winston.transports.Console)(),
        new (winston.transports.File)({ filename: logConf.get('file') })
      ]
    });
  
  require('events').EventEmitter.prototype._maxListeners = 200;
  
  var app = express();
  
  /*Handling CORS*/
  app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    res.header('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
    next();
  });
  
  /*trying to avoid undesirable response code. 
   *Ex: you send 200 and express send 304 ... annoying!
   */
  app.disable('etag');
  
  //setting image dir for static server
  app.use("/tmp", express.static(__dirname + '/tmp'));
  app.use("/public", express.static(__dirname + '/public'));
  app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  //app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  
  //putting modules in the game...
  app.use('/', index);
  app.use('/users', users);
  app.use('/camera', camera);
  app.use('/face', face);
  app.use('/attendance', attendance);
  
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
  
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
  
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    console.error("LOCALS ERRORS: " + res.locals.error);
    console.error("LOCALS MESSAGES: " + err.message);
    JSON.stringify(res.locals.error || err.message)});
  
  });
  
  //Set port
  app.set('port', process.env.PORT || 7000) ;
  
  //setting public on static server
  //app.use(express.static(path.join(__dirname, 'public')));
  
  //setting server up
  var server = app.listen(app.get('port'), function() {
    console.log('Express server listening on port ' + server.address().port);
  });
  
  
  logger.info('starting application');
  
  module.exports = app;
  </code></pre>
  
  <p>The goal is not to configure and instance a new 'winston' object in all modules. I´m a noobie in Node and express, so if you have some documentation about it(I was not able to find out), please point to me! If you prefer to give me the answer directly, better!</p>
  
  <p>Thx!</p>