Problem with buffer and proccess module (node.js)

i think the community hates me becuase the last 2 of my questiones just got no answers i hope this one will.

so i want that the user writes an input and get the buffer of it immidiately , here is my code , but when i write something , nothing happens =

let chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});

process.stdin.on("end", () => {
  const buffer = Buffer.from(chunks);
  process.stdout.write(buffer);
});

ok i solved it =

let chunks = [];

process.stdin.on("data", (data) => {
  chunks.push(data);

  console.log(data);
});

process.stdin.on("end", () => {
  const buffer = Buffer.concat(chunks);
  console.log(buffer);
});

, now i have a new problem
for the output i always get the = 0d 0a (which are line breaks) , in my buffer

i tried =

  const filteredBuffer = buffer.filter(byte => byte !== 0x0d && byte !== 0x0a);
  process.stdout.write(filteredBuffer);

and also =

  const bufferWithoutLineBreaks = buffer.replace(
    (byte) => byte !== 0x0d && byte !== 0x0a);
  process.stdout.write(bufferWithoutLineBreaks);

and yes none of them worked ,
i mean for example when i type the letter p , i get <Buffer 70 0d 0a>
i know 70 is p but the other 2 , are just , i dont want them

i dont know why nobody answered , but you guys where my problem solvers in the past i thought you may can help me now too :smiling_face_with_tear: , (and yes in the past days i tried some other stuff but none of them worked)
@mtf , @cassian-goode , @toastedpitabread , @dakshdeephere

Sorry, I don’t do Node.js, but, if you post a link to the lesson, we can have a look, and maybe learn something new today.

Hi :wave: , no problem .
the buffer method is this = https://www.codecademy.com/courses/learn-node-js/lessons/node-js-essentials/exercises/the-buffer-module

and the , stdout.write is = https://www.codecademy.com/courses/learn-node-js/lessons/node-js-essentials/exercises/user-input-output

How does one run the code?

? ...

you need node =
https://www.codecademy.com/courses/learn-node-js/articles/setting-up-node-locally

I don’t need Node, locally. How does one test the code in the bash console at right of the narrative?

i didnt watched this video but the way i have it , is that i have downloaded it = Node.js — Download Node.js®
and then in vs code , i open a terminal , and run the js file using it ,
1 ) CD (Change Directory) to the directory (folder)
2) Node test.js (for example , or whatever the file name is)

you mean at REPL , where the > is ?

I put ? when it should be, $.

if yes you have to exit it , ctrl+c , if you have linus , well i don’t know , i have windows :):

I’m guessing just,

$ node buffer.js

??

Screenshot 2024-04-17 210314
yes if the file name is Buffer

and then you have to type , because it takes your input and immidiately give its buffer , but as my problem is you get the extra buffers of 0d 0a , which is the enter button

Let me get through the first page, first. It is not letting me,

$ node test.js

Anyway, have to dash for a spell. Back in an hour…

Screenshot 2024-04-17 21aaa0636
the website for all of them = ASCII Table - ASCII codes, hex, decimal, binary, html

i didnt undrestood what you meant

ok no problem

Afraid I’m going to be no help to you since the lesson is not checking my work even after running it in the bash console.

$ node buffer.js
$ node buffer.js
<Buffer 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62>
Buffer 1: <Buffer 68 65 6c 6c 6f> Buffer 2: <Buffer 77 6f 72 6c 64>
<Buffer 68 65 6c 6c 6f 77 6f 72 6c 64>
helloworld
$ 

Since it is not a course I’m taking, or even interested in, I’ll let my frustration win and not bother with a bug report. A buggy SCT is my ticket to exit the course. Sorry.

1 Like

Sorry, I’m still working through the Front-End content, so can’t help with this at present

1 Like