Just redirect
stderr
to
stdout
before piping to
grep:
node a.js 2>&1 | grep "error" > a.log
When using
bash, there is a shorthand for the above:
node a.js |& grep "error" > a.log
With
|&
,
stdout
and
stderr
of the first command are piped to the second. See the
Bash Reference Manual[
^].