index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const express = require("express");
  2. const bodyParser = require("body-parser");
  3. const expressWinston = require("express-winston");
  4. const winston = require("winston");
  5. const router = require("./routes");
  6. const app = express();
  7. const port = 4000; // set our port
  8. app.use(bodyParser.urlencoded({ extended: true }));
  9. app.use(bodyParser.json());
  10. // Place the express-winston logger before the router.
  11. app.use(
  12. expressWinston.logger({
  13. transports: [new winston.transports.Console()],
  14. format: winston.format.combine(
  15. winston.format.colorize(),
  16. winston.format.simple()
  17. ),
  18. meta: true,
  19. msg: "HTTP {{req.method}} {{req.url}}",
  20. expressFormat: true,
  21. colorize: true,
  22. responseWhitelist: [...expressWinston.requestWhitelist, "body"]
  23. })
  24. );
  25. app.use("/api", router);
  26. // Place the express-winston errorLogger after the router.
  27. app.use(
  28. expressWinston.errorLogger({
  29. transports: [new winston.transports.Console()],
  30. format: winston.format.combine(
  31. winston.format.colorize(),
  32. winston.format.json()
  33. )
  34. })
  35. );
  36. app.listen(port);
  37. /* eslint no-console:0 */
  38. console.log("Mock is on " + port);