title: NodeJS - How is logger object shared across project?
body: <p>I have created a <code>logger</code> object in <code>utils/logger.js</code> using the <code>winston</code> package. The entry-point for my project is <code>index.js</code> where I have <code>const logger = require('./utils/logger')</code>. How do I 'cascade' this logger object across <em>all</em> of project files (~20)? Should each file in my project also do a <code>const logger = require('../utils/logger)</code> ? If so, aren't they all individual <code>logger</code> objects when I do a <code>node index.js</code>?</p>
  
  <p>I am using the following (from <a href="https://www.digitalocean.com/community/tutorials/how-to-use-winston-to-log-node-js-applications" rel="nofollow noreferrer">here</a>) for <code>utils.logger.js</code>.</p>
  
  <pre class="lang-js prettyprint-override"><code>var appRoot = require('app-root-path');
  var winston = require('winston');
  
  // define the custom settings for each transport (file, console)
  var options = {
    file: {
      level: 'info',
      filename: `${appRoot}/logs/app.log`,
      handleExceptions: true,
      json: true,
      maxsize: 5242880, // 5MB
      maxFiles: 5,
      colorize: false,
    },
    console: {
      level: 'debug',
      handleExceptions: true,
      json: false,
      colorize: true,
    },
  };
  
  // instantiate a new Winston Logger with the settings defined above
  var logger = new winston.Logger({
    transports: [
      new winston.transports.File(options.file),
      new winston.transports.Console(options.console)
    ],
    exitOnError: false, // do not exit on handled exceptions
  });
  
  // create a stream object with a 'write' function that will be used by `morgan`
  logger.stream = {
    write: function(message, encoding) {
      // use the 'info' log level so the output will be picked up by both transports (file and console)
      logger.info(message);
    },
  };
  
  module.exports = logger;
  </code></pre>