Code Monkey home page Code Monkey logo

node-nodejs-basics's Introduction

Assignment: Node.js basics

Description

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

Technical requirements

  • 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

Subtasks

File system (src/fs)

You should implement several functions in dedicated files

  • create.js - implement function that creates new file fresh.txt with content I am fresh and young inside of the files folder (if file already exists Error with message FS operation failed must be thrown)
  • copy.js - implement function that copies folder files files with all its content into folder files_copy at the same level (if files folder doesn't exists or files_copy has already been created Error with message FS operation failed must be thrown)
  • rename.js - implement function that renames file wrongFilename.txt to properFilename with extension .md (if there's no file wrongFilename.txt or properFilename.md already exists Error with message FS operation failed must be thrown)
  • delete.js - implement function that deletes file fileToRemove.txt (if there's no file fileToRemove.txt Error with message FS operation failed must be thrown)
  • list.js - implement function that prints all array of filenames from files folder into console (if files folder doesn't exists Error with message FS operation failed must be thrown)
  • read.js - implement function that prints content of the fileToRead.txt into console (if there's no file fileToRead.txt Error with message FS operation failed must be thrown)

Command line interface(src/cli)

You should implement several functions in dedicated files

  • env.js - implement function that parses environment variables with prefix RSS_ and prints them to the console in the format RSS_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 format propName is value, prop2Name is value2

Modules(src/modules)

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 to esm.mjs)

Hash (src/hash)

You should implement several functions in dedicated files

  • calcHash.js - implement function that calculates SHA256 hash for file fileToCalculateHashFor.txt and logs it into console as hex using Streams API

Streams (src/streams)

You should implement several functions in dedicated files

  • read.js - implement function that reads file fileToRead.txt content using Readable Stream and prints it's content into process.stdout
  • write.js - implement function that writes process.stdin data into file fileToWrite.txt content using Writable Stream
  • transform.js - implement function that reads data from process.stdin, reverses text using Transform Stream and then writes it into process.stdout

Zlib (src/zip)

You should implement several functions in dedicated files

  • compress.js - implement function that compresses file fileToCompress.txt to archive.gz using zlib and Streams API
  • decompress.js - implement function that decompresses archive.gz back to the fileToCompress.txt with same content as before compression using zlib and Streams API

Worker Threads (src/wt)

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 thread
  • main.js - implement function that creates number of worker threads (equal to the number of host machine logical CPU cores) from file worker.js and able to send data to those threads and to receive result of the computation from them. You should send incremental number starting from 10 to each worker. For example: on host machine with 4 cores you should create 4 workers and send 10 to first worker, 11 to second worker, 12 to third worker, 13 to fourth worker. 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 from worker or 'error' in case of error in worker
    • data - value from worker in case of success or null in case of error in worker

The results in the array must be in the same order that the workers were created

Child Processes (src/cp)

You should implement several functions in dedicated files

  • cp.js - implement function spawnChildProcess that receives array of arguments args and creates child process from file script.js, passing these args to it. This function should create IPC-channel between stdin and stdout of master process and child process:
    • child process stdin should receive input from master process stdin
    • child process stdout should send data to master process stdout

node-nodejs-basics's People

Contributors

alreadybored avatar sashtje avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.