0

Let's say there is a file demo.js. If I run it like this:

$ node demo.js | grep keyword 

then I can get a string which is returned by demo.js and then use grep to handle it.

My question is how to return the string in demo.js?

3
  • You mean you want the output of the demo.js to be served as input to the same demo.js ? Commented Jul 20, 2018 at 9:13
  • to grep, not to the same demo.js Commented Jul 20, 2018 at 9:16
  • did you try console.log("your message") ? Commented Jul 20, 2018 at 9:17

2 Answers 2

1
process.stdout.write 

I found this is correct.

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

1 Comment

And you found console.log() wrong ? In fact, console.log() internally uses process.stdout.write but with little bit of formatting. Also, stdout.write will not print a newline automatically, so .. you cant "really" use process.stdout.write to work with grep correctly (unless you add \n yourself, which will be a complete waste)
0

To print a string in a NodeJs application simply use console.log()

Example :

console.log("This is the message");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.