Error: write after end
See original GitHub issueNode version: 8.11.3
OS: 64 bit Windows 10
I am using rotating-file-stream
and morgan
in my application to log all HTTP requests into daily rotated file. I have followed closely with the way that the docs of morgan
recommended to use RFS:
https://github.com/expressjs/morgan#log-file-rotation
Code:
app.js
// define the log directory
let logDirectory = path.join(__dirname, 'log');
// ensure log directory exists
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory);
// create a rotating write stream
let writeStream = rfs((time) => {
if (!time) {
return 'access.log';
}
let t = moment(time);
return `${t.format('MM-DD-YYYY')}.log`;
}, {
interval: '1d', // daily rotate
path: logDirectory,
rotationTime: false,
});
// set the logger, logging every request to the console
app.use(morgan('common', {
stream: writeStream,
}));
Error message:
events.js:183
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (_stream_writable.js:236:12)
at RotatingFileStream.Writable.write (_stream_writable.js:287:5)
at Array.logRequest (C:\Haoyang\source_code\myapp\server\node_modules\morgan\index.js:130:14)
at listener (C:\Haoyang\source_code\myapp\server\node_modules\on-finished\index.js:169:15)
at onFinish (C:\Haoyang\source_code\myapp\server\node_modules\on-finished\index.js:100:5)
at callback (C:\Haoyang\source_code\myapp\server\node_modules\ee-first\index.js:55:10)
at ServerResponse.onevent (C:\Haoyang\source_code\myapp\server\node_modules\ee-first\index.js:93:5)
at emitNone (events.js:111:20)
at ServerResponse.emit (events.js:208:7)
at onFinish (_http_outgoing.js:720:10)
My goal is quite simple: I just want to let morgan
direct all its log into the rotating write stream created via RFS, with filename to be in MM-DD-YYYY.log
format for each day. I do a check to return a fixed file name access.log
for the case when the time
parameter is null
. However, the error still persists
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Write After End error in node.js webserver - Stack Overflow
I am struggling with my node.js hobby project due to a "write after end" Error. I have a created a node.js webserver that...
Read more >write after end · Issue #928 · tulios/kafkajs - Connection error
After the update, we noticed that a new error is logged in our production server: Message: Connection error: write after end Stack: Error ......
Read more >Server crashes with even simplest code. : r/node - Reddit
this is error events.js:352 throw er; // Unhandled 'error' event Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd…
Read more >Error: write after end (Example) | Treehouse Community
Node is asynchronous, which means that functions happen at the same time. Write after end means that something is being written after the...
Read more >Object Storage upload: [ERR_STREAM_WRITE_AFTER_END]
Hey guys! I use aws-sdk for NodeJS for Linode Object Storage but I get the following error `[ERR_STREAM_WRITE_AFTER_END]: write after end` when uploading ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This config seems work for me by adding
immutable: true,
:@bryandbor : I believe
rotationTime: true
meanstime
parameter will be fixed to the moment that you call the function( run the server up ).Hi @HaoyangFan96,
plz try to add following code just after
let writeStream = ...
statement:The first error should help you finding the root cause of your problem.
Hope this helps, iCC