1

I've been trying to use the https package to make some API calls, but when it comes to printing the result, it seems that only process.stdout.write() returns an unformatted JSON body, while console.log() returns a Buffer:

<Buffer 7b 22 74 6f 6b 65 6e 5f 74 79 70 65 22 3a 22 42 65 61 72 65 72 22 2c 22 65 78 70 69 72 65 73 5f 69 6e 22 3a 33 36 30 30 2c 22 61 63 63 65 73 73 5f 74 ... 808 more bytes>

So my question is, what's the difference between these two functions since NodeJS' documentation is saying that they're almost the same, the only difference being a newline.

Gabe
  • 23
  • 5
  • What do you mean by a JSON body? JSON is a string which both console.log and stdout should be identical in outputting. – evolutionxbox Nov 29 '21 at 10:40
  • 1
    `console.log` does formatting and pretty-printing, `stdout.write` expects a string. – Bergi Nov 29 '21 at 10:43
  • 1
    Using console.log for a variable showed a lot of unreadable characters while using process.stdout.write showed an object. – Ejaz khan Nov 29 '21 at 14:03
  • 1
    looking at the Node docs apparently console.log is just process.stdout.write with a line-break at the end: Source: http://nodejs.org/docs/v0.3.1/api/process.html#process.stdout – Ejaz khan Nov 29 '21 at 14:03

0 Answers0