Skip to content

Utilities for redirecting node process stdout and stderr.

License

Notifications You must be signed in to change notification settings

duncaan/redirect-stdio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redirect-stdio

Utilities for redirecting node process stdout and stderr.

Note: Only works on MacOS and Linux.

Motivation

Imagine you have a node app that logs to stdout and a bash script that runs your node process like this:

node myapp.js >> access.log

Later, you want to add logrotate, which moves access.log to access.log.2 and then calls SIGUSR2 on your node process. But your node process is logging to stdout, and can't exactly "reopen" process.stdout.

With redirect-stio, you can:

  • use pathFromFd to find where your process's stdout is actually going
  • on SIGUSR2, re-open the log path you just found, and write that file descriptor over the old one to rotate logs

Usage

const { reopenStdout, reopenStderr } = require('redirect-stdio');

process.on('SIGUSR2', function() {
  reopenStdout();
  reopenStderr();
});

License

Copyright 2023 Movable, Inc. See LICENSE.md.

About

Utilities for redirecting node process stdout and stderr.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 69.5%
  • C 29.8%
  • Python 0.7%