In the index.js
file in the 02-write-file
directory, develop a script that outputs a greeting to the console, waits for text input, and writes the entered text to a file.
- The use of any third-party modules is prohibited.
- Each task must be executed in the root directory using the command
node <task folder name>
. - The use of synchronous functions from the fs module, such as
fs.statSync(path[, options])
,fs.readFileSync(path[, options])
, and others found in the synchronous API section, is prohibited.
- Inside the
02-write-file
folder, there is 1 fileindex.js
. - When executing the command
node 02-write-file
in the root directory of the repository, a text file is created in the02-write-file
folder, and a prompt for text input is displayed in the console (the text of prompt is of your choice). - After entering text, the entered text should be written to the previously created file in the
02-write-file
directory. The process does not terminate and awaits new input. - After the next input, the initially created text file is appended with new text, and the process continues to wait for input.
- When pressing the
ctrl + c
key combination or enteringexit
into the console, a farewell phrase is displayed (the text of farewell phrase is of your choice), and the process terminates.
- Strengthen understanding of the basics of working with events and streams in Node.js.
- Work with the global process object.
In this task, you will develop a program that reads your console input until the process is forcibly terminated with ctrl + c
or the keyword exit
is entered.
The steps to complete the task are as follows:
- Import all required modules.
- Create a writable stream to a text file.
- Display a welcome message in the console.
- Wait for user input, with subsequent checking for the presence of the keyword
exit
. - Write the entered text to the file.
- Wait for further input.
- Implement a farewell message when the process is stopped.
To successfully complete this task, you will need to apply your knowledge of events and streams that you have acquired previously. Additionally, an understanding of the global process object and its capabilities is essential. Utilizing its events allows you to intercept signals sent to the process, such as the ctrl + c
interrupt command.
Reading anything from a stream using the Readline module can be helpful. The standard input stream stdin
, being a ReadableStream, is well-suited for this.
Please note, if you are seeking information in Russian, be aware that translations of the documentation may be outdated. They might not include all the latest features of the modules. For the most current and accurate information, always refer to the official documentation!
- Process:
- Readline:
- Events:
- Streams:
- Path Module: