1.1.1 • Published 3 years ago

@mashthekeys/response-console v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

@mashthekeys/response-console

NPM

Creates a buffered console object on a Response object, which outputs to its parent console when the response finishes. Comes with middleware for server logging by request.

Intended to help logs remain coherent in high-concurrency applications, where asynchronous processes to load files or query databases can otherwise result in jumbled logs.

Examples

Basic usage

const responseConsole = require("@mashthekeys/response-console");

createServer(function (req, res) {
  responseConsole(res, console)

  console.log("This output appears immediately.")

  res.console.log("This will only output to console when the response is finished.")

  someAsyncProcess(req, res)
    .then(data => {
      res.console.log("Process completed, response is about to finish.")

      res.end(data)
    })
});

Outputting to a custom console

const responseConsole = require("@mashthekeys/response-console");

const logger = require("some-package")();

createServer(function(req, res) {
  responseConsole(res, logger)
  
  res.console.log("This will be appended to the log when the response is finished.")

  logger.log("This log message appears immediately.")
  
  someAsyncProcess().then(data => res.end(data))
});

Log every request to console

const app = require("express")();
const responseConsole = require("@mashthekeys/response-console");

app.all("*", responseConsole.middleware(console))
1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago