I do not understand the stream in node well. I try to save my app's request and response information to the mongodb.
Firstly, I want to set a variable to the result of morgan:
var apiInfo = morgan('dev')
app.use(console.log('test______',apiInfo))
However, it does not work. I know this in the morgan official site:
var express = require('express')
var fs = require('fs')
var morgan = require('morgan')
var path = require('path')
var app = express()
// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), {flags: 'a'})
// setup the logger
app.use(morgan('combined', {stream: accessLogStream}))
app.get('/', function (req, res) {
res.send('hello, world!')
})
But I do not want to save the result to the access.log, and I just want to save the result to a variable apiInfo.