2

I have a large app output , and I should analyse the output.

It's difficult to do it on the terminal so I would print the output into a file to analyse it easier.

So how can I redirect nodejs app.js output into a file in Ubuntu ?

3
  • are we on server side in nodejs ? Then look at the fs (filesystem) module. You made have to make a JSON.stringify to change the json to a text-string Commented Aug 23, 2018 at 15:22
  • I'm working on local Commented Aug 23, 2018 at 15:34
  • 1
    Are you trying to capture whatever nodejs puts onto your terminal into a file instead? Commented Aug 23, 2018 at 15:37

1 Answer 1

2

You can do it by redirecting your app's output (stdout and stderr) to the desired file:

$ node app.js &> filename.txt

If you do this, everything that you log using console.log() and console.err() will be included in your file.

Of course, it would be better if you programmatically write to a file so you can include only what you want to keep in the file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.