If you want to capture the output of stdout and stderr from a command in terminal into a file:

$ npm list |& tee list.txt