node+express+morgan自定义 morgan 以捕获响应内容

//1.导入模块

const run = require('./run.js')

const express = require('express')

const morgan = require('morgan');

const socket = require('./api/socket.js');

const tools = require('./api/tools.js');

// 定义颜色常量

const RESET = '\x1b[0m';

const RED = '\x1b[31m';

const GREEN = '\x1b[32m';

const YELLOW = '\x1b[33m';

const BLUE = '\x1b[34m';



 

//当前日期

console.log(YELLOW + '---------------' + tools.getDate())

console.log(YELLOW + '启动服务....')

//2.创建服务器

let app = express()

//server.use(express.urlencoded()) //中间件要写在启动文件里面

app.use(express.urlencoded({

    extended: false

}));

app.use(express.json());

// 解析 url-encoded格式的表单数据1

// var bodyParser = require('body-parser')

// app.use(bodyParser.urlencoded({ extended: false }))

// app.use(bodyParser.json())

// 解析 url-encoded格式的表单数据2

// app.use(express.urlencoded({ extended: false }));

// app.use(express.json());

// 一定要在路由之前,配置 cors 这个中间件,从而解决接口跨域的问题

const cors = require('cors')

app.use(cors())

//日志系统Demo

const FileStreamRotator = require('file-stream-rotator');

const fs = require('fs');

const path = require('path');

const { log } = require('console');

//const logDirectory = path.join(__dirname, 'log');

const logDirectory =

上一篇:【项目配置文件】TypeScript 编译器的配置文件-前言


下一篇:docker-compose查看容器日志和实时查看日志