Guest User

Untitled

a guest
Mar 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const { appendFileSync } = require('fs');
  2.  
  3. // Debug
  4. // process.on('uncaughtException', (err) => {
  5. // appendFileSync('/Users/justin/GitHub/node-message-forwarder/log', `${err}\n\n`);
  6. // });
  7.  
  8. var stdin = process.stdin;
  9.  
  10. // Debug
  11. // if (stdin.isTTY) {
  12. // stdin.setRawMode(true);
  13. // }
  14.  
  15. stdin.resume();
  16.  
  17. // on any data into stdin
  18. stdin.on('data', (data) => {
  19. // First 4 bytes are actually the length of the message from Chrome. Since {data} is a Buffer here,
  20. // we can just call toString(). In C, though, we will use the first 4 bytes to get the message length
  21. // and allocate a string of the contents before forwarding the message as JSON to the right address.
  22. const err = appendFileSync('/Users/justin/GitHub/node-message-forwarder/log', `${data.toString().substr(1)}\n\n`);
  23. });
Add Comment
Please, Sign In to add comment