Your task is to complete several simple tasks to learn Node.js basics
Fork this repository
Assignment contains several nested folders inside src
. Your task is to implement necessary functionality inside them
- Any external tools and libraries are prohibited
- Use 18 LTS version of Node.js
- Don't change signature of pre-written functions (e.g. don't rename them, don't make them synchronous, etc.)
- Prefer asynchronous API whenever possible
You should implement several functions in dedicated files
create.js
- implement function that creates new filefresh.txt
with contentI am fresh and young
inside of thefiles
folder (if file already existsError
with messageFS operation failed
must be thrown)copy.js
- implement function that copies folderfiles
files with all its content into folderfiles_copy
at the same level (iffiles
folder doesn't exists orfiles_copy
has already been createdError
with messageFS operation failed
must be thrown)rename.js
- implement function that renames filewrongFilename.txt
toproperFilename
with extension.md
(if there's no filewrongFilename.txt
orproperFilename.md
already existsError
with messageFS operation failed
must be thrown)delete.js
- implement function that deletes filefileToRemove.txt
(if there's no filefileToRemove.txt
Error
with messageFS operation failed
must be thrown)list.js
- implement function that prints all array of filenames fromfiles
folder into console (iffiles
folder doesn't existsError
with messageFS operation failed
must be thrown)read.js
- implement function that prints content of thefileToRead.txt
into console (if there's no filefileToRead.txt
Error
with messageFS operation failed
must be thrown)
You should implement several functions in dedicated files
env.js
- implement function that parses environment variables with prefixRSS_
and prints them to the console in the formatRSS_name1=value1; RSS_name2=value2
args.js
- implement function that parses command line arguments (given in format--propName value --prop2Name value2
, you don't need to validate it) and prints them to the console in the formatpropName is value, prop2Name is value2
You should refactor file (you can add additional imports if needed)
cjsToEsm.cjs
- rewrite it to it's equivalent in ECMAScript notation (and rename it toesm.mjs
)
You should implement several functions in dedicated files
calcHash.js
- implement function that calculates SHA256 hash for filefileToCalculateHashFor.txt
and logs it into console ashex
You should implement several functions in dedicated files
read.js
- implement function that reads filefileToRead.txt
content using Readable Stream and prints it's content intoprocess.stdout
write.js
- implement function that writesprocess.stdin
data into filefileToWrite.txt
content using Writable Streamtransform.js
- implement function that reads data fromprocess.stdin
, reverses text using Transform Stream and then writes it intoprocess.stdout
You should implement several functions in dedicated files
compress.js
- implement function that compresses filefileToCompress.txt
toarchive.gz
usingzlib
and Streams APIdecompress.js
- implement function that decompressesarchive.gz
back to thefileToCompress.txt
with same content as before compression usingzlib
and Streams API
You should implement several functions in dedicated files
worker.js
- extend given function to work with data received from main thread and implement function which sends result of the computation to the main threadmain.js
- implement function that creates number of worker threads (equal to the number of host machine logical CPU cores) from fileworker.js
and able to send data to those threads and to receive result of the computation from them. You should send incremental number starting from10
to eachworker
. For example: on host machine with 4 cores you should create 4 workers and send 10 to firstworker
, 11 to secondworker
, 12 to thirdworker
, 13 to fourthworker
. After all workers will finish, function should log array of results into console. The results are array of objects with 2 properties:status
-'resolved'
in case of successfully received value fromworker
or'error'
in case of error inworker
data
- value fromworker
in case of success ornull
in case of error in worker
The results in the array must be in the same order that the workers were created
You should implement several functions in dedicated files
cp.js
- implement functionspawnChildProcess
that receives array of argumentsargs
and creates child process from filescript.js
, passing theseargs
to it. This function should create IPC-channel betweenstdin
andstdout
of master process and child process:- child process
stdin
should receive input from master processstdin
- child process
stdout
should send data to master processstdout
- child process