There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Node.js doc suggests that sometimes we should not call process.exit() explicitly, which may make the data print to stdout lost. So how to make the game.js better?
There is no loop. Since we declare an event listener, Node.js will wait for the emitting of the data event. Right after the event is fired, Node.js invoke the callback function and then return to the waiting state, waiting for the next event.
Because from the game module we are exporting an object with one property (testNumber) and here
In app.js we are destructuring that property from the object.
In computer science, a data buffer (or just buffer ) is a region of a physical memory storage used to temporarily store data while it is being moved from one place to another. … However, a buffer may be used when moving data between processes within a computer . This is comparable to buffers in telecommunication. Buffer in Node is a class and when you const myBuffer = new Buffer() do this(the new keyword uses the constructor of that class to create an instance of the class, so in this case myBuffer is an instance of the Buffer class.
Thank you for your response. Destructuring was what I was looking for. Codecademy didn’t not teach that prior to it’s use in another example of pushing the teaching responsibility onto the student.
Does the first argument for process.stdin.on() always have to be ‘data’ or can it be any string we have created?
process.stdin.on('data', playGame);
process.stdin.on('random', playGame);
When I change ‘data’ to ‘random’ I get the below error in the terminal?
node app.js
I’m thinking of a number from 1 through 10. What do you think it is?
(Write “quit” to give up.)
Is the number … $ 5
bash: 5: command not found
I thought its similar to an instance of the EventEmitter where in the on() method we can pass anything as an string as an event to be listened out for. Or is that a incorrect assumption?
for example
// Assign the newUserListener function as the listener callback for 'new user' events
myEmitter.on('new user', newUserListener)
// Emit a 'new user' event
myEmitter.emit('new user', 'Lily Pad')
I assume 'new user could be changed for another string of your choice and the code will still work. So why does it not work for process.stdin.on(‘data’, playGame); ?
I had the same question just now. I did some digging in the documentation of node and in stackoverflow, and what I found is that (to my understanding) stdin and stdout is a stream (in prior lessons in node there were explanations about writable, readable and duplex streams types). In our case, stdin is a readable stream, and readable stream has built in events such as “data” and some others. Here is the link to the documentation, it should help. Stream | Node.js v17.5.0 Documentation