Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Assignments_v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# [Course program (for RS School students)](https://github.com/rolling-scopes-school/tasks/blob/master/node/README.md)

# Node.js Assignments

## Node.js basics
- [Assignment](assignments/nodejs-basics/assignment.md)
- [Scoring](assignments/nodejs-basics/score.md)
- [Cross-Check manual](assignments/nodejs-basics/cross-check-manual.md)

## File Manager
- [Assignment](assignments/file-manager/assignment.md)
- [Scoring](assignments/file-manager/score.md)

## Basic Testing
- [Assignment](assignments/basic-testing/assignment.md)
- [Scoring](assignments/basic-testing/score.md)

## Simple CRUD API
- [Assignment](assignments/crud-api/assignment.md)
- [Scoring](assignments/crud-api/score.md)

## Battleship backend
- [Assignment](assignments/battleship/assignment.md)
- [Scoring](assignments/battleship/score.md)

## GraphQL service
- [Assignment](assignments/graphql-service/assignment.md)
- [Scoring](assignments/graphql-service/score.md)

## REST Service: Basic
- [Assignment](assignments/rest-service/assignment.md)
- [Scoring](assignments/rest-service/score.md)

## REST service: Database & ORM
- [Assignment](assignments/database-orm/assignment.md)
- [Scoring](assignments/database-orm/score.md)

## REST service: Logging & Error handling
- [Assignment](assignments/logging-error-handling/assignment.md)
- [Scoring](assignments/logging-error-handling/score.md)

## REST service: Authentication & Authorization
- [Assignment](assignments/authentication/assignment.md)
- [Scoring](assignments/authentication/score.md)

## REST service: Containerization
- [Assignment](assignments/containerization/assignment.md)
- [Scoring](assignments/containerization/score.md)
78 changes: 42 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
# [Course program (for RS School students)](https://github.com/rolling-scopes-school/tasks/blob/master/node/README.md)
# Node.js Assignments v2

# Node.js Assignments
## Node.js Basics
- [Assignment](assignments-v2/01a-nodejs-basics/assignment.md)
- [Scoring](assignments-v2/01a-nodejs-basics/score.md)

## Node.js basics
- [Assignment](assignments/nodejs-basics/assignment.md)
- [Scoring](assignments/nodejs-basics/score.md)
- [Cross-Check manual](assignments/nodejs-basics/cross-check-manual.md)
## Data Processing CLI
- [Assignment](assignments-v2/01b-data-processing-cli/assignment.md)
- [Scoring](assignments-v2/01b-data-processing-cli/score.md)

## File Manager
- [Assignment](assignments/file-manager/assignment.md)
- [Scoring](assignments/file-manager/score.md)
## CRUD API
- [Assignment](assignments-v2/02-crud-api/assignment.md)
- [Scoring](assignments-v2/02-crud-api/score.md)

## Basic Testing
- [Assignment](assignments/basic-testing/assignment.md)
- [Scoring](assignments/basic-testing/score.md)
## Fastify REST API
- [Assignment](assignments-v2/03-fastify-rest-api/assignment.md)
- [Scoring](assignments-v2/03-fastify-rest-api/score.md)

## Simple CRUD API
- [Assignment](assignments/crud-api/assignment.md)
- [Scoring](assignments/crud-api/score.md)
## REST service: Database & Prisma ORM
- [Assignment](assignments-v2/04-database-prisma/assignment.md)
- [Scoring](assignments-v2/04-database-prisma/score.md)

## Battleship backend
- [Assignment](assignments/battleship/assignment.md)
- [Scoring](assignments/battleship/score.md)
## REST service: Authentication & Authorization
- [Assignment](assignments-v2/05-auth-jwt/assignment.md)
- [Scoring](assignments-v2/05-auth-jwt/score.md)

## GraphQL service
- [Assignment](assignments/graphql-service/assignment.md)
- [Scoring](assignments/graphql-service/score.md)
## REST service: Testing
- [Assignment](assignments-v2/06a-testing/assignment.md)
- [Scoring](assignments-v2/06a-testing/score.md)

## REST Service: Basic
- [Assignment](assignments/rest-service/assignment.md)
- [Scoring](assignments/rest-service/score.md)
## REST service: Logging & Error Handling
- [Assignment](assignments-v2/06b-logging-errors/assignment.md)
- [Scoring](assignments-v2/06b-logging-errors/score.md)

## REST service: Database & ORM
- [Assignment](assignments/database-orm/assignment.md)
- [Scoring](assignments/database-orm/score.md)
## REST service: Containerization & Docker
- [Assignment](assignments-v2/07-docker/assignment.md)
- [Scoring](assignments-v2/07-docker/score.md)

## REST service: Logging & Error handling
- [Assignment](assignments/logging-error-handling/assignment.md)
- [Scoring](assignments/logging-error-handling/score.md)
## WebSocket: Live Quiz Game
- [Assignment](assignments-v2/08-websockets/assignment.md)
- [Scoring](assignments-v2/08-websockets/score.md)

## REST service: Authentication & Authorization
- [Assignment](assignments/authentication/assignment.md)
- [Scoring](assignments/authentication/score.md)
## AI/LLM Integration
- [Assignment](assignments-v2/09-ai-llm-integration/assignment.md)
- [Scoring](assignments-v2/09-ai-llm-integration/score.md)

## AI RAG & Vector Database
- [Assignment](assignments-v2/10-ai-rag-vectordb/assignment.md)
- [Scoring](assignments-v2/10-ai-rag-vectordb/score.md)

---

## REST service: Containerization
- [Assignment](assignments/containerization/assignment.md)
- [Scoring](assignments/containerization/score.md)
## Previous version
- [Assignments v1](Assignments_v1.md)
120 changes: 120 additions & 0 deletions assignments-v2/01a-nodejs-basics/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Assignment: Node.js Basics

## Description

Your task is to complete several tasks to learn Node.js core APIs. Each subtask is a standalone exercise in a dedicated file inside the corresponding subfolder of `src/`.

Fork the starter repository and implement the required functionality.

## Technical requirements

- Any external tools and libraries are prohibited
- Use 24.x.x version (24.10.0 or upper) of Node.js
- Don't change the 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:

- `snapshot.js` — implement function that recursively scans the `workspace` directory and writes a `snapshot.json` file next to it. The JSON file should contain a flat array of all entries with file contents:
```json
[
{ "path": "file1.txt", "type": "file", "size": 1024, "content": "file contents as base64 string" },
{ "path": "subdir", "type": "directory" },
{ "path": "subdir/nested.txt", "type": "file", "size": 512, "content": "nested file contents as base64 string" }
]
```
Paths should be relative to `workspace`. Size is in bytes (only for files). File contents should be stored as base64-encoded strings. If `workspace` doesn't exist, `Error` with message `FS operation failed` must be thrown.

- `restore.js` — implement function that reads `snapshot.json` and recreates the directory/file structure described in it inside a `workspace_restored` folder. Directories should be created, files should be recreated with their original content (decoded from base64). If `snapshot.json` doesn't exist, `Error` with message `FS operation failed` must be thrown. If `workspace_restored` already exists, `Error` with message `FS operation failed` must be thrown.

- `findByExt.js` — implement function that recursively finds all files with a specific extension inside the `workspace` directory and prints their relative paths sorted alphabetically, one per line. The extension is provided as a CLI argument `--ext <extension>` (e.g. `--ext txt` or `--ext js`). If the `--ext` argument is not provided, default to `.txt`. If `workspace` doesn't exist, `Error` with message `FS operation failed` must be thrown.

- `merge.js` — implement function that reads all `.txt` files from the `workspace/parts` folder in alphabetical order by filename, concatenates their content (separated by newline), and writes the result to `workspace/merged.txt`. If the `parts` folder doesn't exist or contains no `.txt` files, `Error` with message `FS operation failed` must be thrown.

### CLI (src/cli)

You should implement several functions in dedicated files:

- `interactive.js` — implement a simple interactive command-line interface using the `readline` module. The program should:
- Display a prompt `> ` and wait for user input
- Support the following commands:
- `uptime` — prints process uptime in seconds (e.g. `Uptime: 12.34s`)
- `cwd` — prints the current working directory
- `date` — prints the current date and time in ISO format
- `exit` — prints `Goodbye!` and terminates the process
- On unknown command, print `Unknown command`
- On `Ctrl+C` or end of input, print `Goodbye!` and exit

- `progress.js` — implement a function that simulates a progress bar in the terminal. The bar should go from 0% to 100% over approximately 5 seconds, updating in place (using `\r`) every 100ms. The output format should be: `[████████████████████ ] 67%` (30-character bar). When complete, print `Done!` on a new line.

### Modules (src/modules)

You should implement a function in a dedicated file:

- `dynamic.js` — implement a function that accepts a plugin name as a command line argument and dynamically imports the corresponding module from the `plugins/` subdirectory. Each plugin module exports a `run()` function that returns a string. After importing, call `run()` and print the result. Three plugins are pre-created: `uppercase.js`, `reverse.js`, `repeat.js`. If the plugin doesn't exist, print `Plugin not found` and exit with code 1.

### Hash (src/hash)

You should implement a function in a dedicated file:

- `verify.js` — implement function that reads a `checksums.json` file containing an object where keys are filenames and values are expected SHA256 hex hashes:
```json
{
"file1.txt": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824",
"file2.txt": "486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7"
}
```
For each file listed, calculate its actual SHA256 hash using Streams API and print the result:
```
file1.txt — OK
file2.txt — FAIL
```
If `checksums.json` doesn't exist, `Error` with message `FS operation failed` must be thrown.

### Streams (src/streams)

You should implement several functions in dedicated files:

- `lineNumberer.js` — implement function that reads data from `process.stdin`, prepends each line with its line number (starting from 1) using a Transform Stream, and writes the result to `process.stdout`. Example: input `hello\nworld` → output `1 | hello\n2 | world`

- `filter.js` — implement function that reads data from `process.stdin`, filters only lines that contain a pattern (given as a CLI argument `--pattern <string>`), and writes matching lines to `process.stdout` using a Transform Stream

- `split.js` — implement function that reads file `source.txt` using a Readable Stream and splits it into chunk files: `chunk_1.txt`, `chunk_2.txt`, etc. Each chunk should contain at most N lines (N is given as a CLI argument `--lines <number>`, default: 10). Must use Streams API.

### Zlib (src/zip)

You should implement several functions in dedicated files:

- `compressDir.js` — implement function that reads all files from the `workspace/toCompress/` directory, recursively compresses the entire directory structure (preserving directory paths and file names) into a single `.br` archive file `archive.br` and saves it to `workspace/compressed/` directory (creating it if it doesn't exist). Must use Streams API. If `toCompress` doesn't exist, `Error` with message `FS operation failed` must be thrown.

- `decompressDir.js` — implement function that reads the `archive.br` file from `workspace/compressed/`, decompresses it, and extracts the original directory structure with all files to `workspace/decompressed/` directory (creating it if it doesn't exist). The decompressed content must match the original. If `compressed` doesn't exist or `archive.br` doesn't exist, `Error` with message `FS operation failed` must be thrown.

### Worker Threads (src/wt)

You should implement several functions in dedicated files:

- `worker.js` — implement a function that receives an array of numbers from the main thread, sorts them in ascending order, and sends the sorted array back to the main thread

- `main.js` — implement function that reads a JSON file `data.json` containing an array of numbers (e.g. `[5, 3, 8, 1, 9, 2, ...]`). The function should:
1. Split the array into N chunks (where N = number of logical CPU cores)
2. Create N worker threads from `worker.js`, sending one chunk to each
3. Collect sorted chunks from all workers
4. Merge the sorted chunks into a single sorted array (using k-way merge algorithm)
5. Log the final sorted array to the console

The results must be collected in the same order as workers were created.

### Child Processes (src/cp)

You should implement a function in a dedicated file:

- `execCommand.js` — implement function `execCommand` that takes a command string as a CLI argument (e.g. `node src/cp/execCommand.js "ls -la"`), spawns it as a child process using `spawn`, and:
- pipes the child's `stdout` to `process.stdout`
- pipes the child's `stderr` to `process.stderr`
- passes environment variables from the parent process to the child process
- when the child exits, the parent process exits with the same exit code

43 changes: 43 additions & 0 deletions assignments-v2/01a-nodejs-basics/score.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Scoring: Node.js Basics

## Check

For check simplification you have npm-scripts in `package.json`.
NB! Some scripts have predefined data (e.g. environment variables, CLI arguments). Feel free to change it during the check if necessary.

## Basic Scope

- File System (src/fs)
- **+10** `snapshot.js` implemented properly (recursive scan, correct JSON structure with path/type/size)
- **+10** `restore.js` implemented properly (reads snapshot, recreates structure)
- **+6** `findByExt.js` implemented properly (recursive search, sorted output)
- **+6** `merge.js` implemented properly (reads .txt files in order, concatenates, writes result)
- CLI (src/cli)
- **+10** `interactive.js` implemented properly (readline prompt, supports uptime/cwd/date/exit commands, handles Ctrl+C)
- **+6** `progress.js` implemented properly (in-place updating progress bar, 0-100% over ~5 seconds)
- Modules (src/modules)
- **+10** `dynamic.js` implemented properly (dynamic import from plugins/, calls run(), handles missing plugin)
- Hash (src/hash)
- **+12** `verify.js` implemented properly (reads checksums.json, calculates SHA256 via Streams, prints OK/FAIL per file)
- Streams (src/streams)
- **+10** `lineNumberer.js` implemented properly (Transform stream, prepends line numbers)
- **+10** `filter.js` implemented properly (Transform stream, filters by pattern from CLI arg)
- **+10** `split.js` implemented properly (Readable stream, splits file into chunks by line count)
- Zlib (src/zip)
- **+10** `compressDir.js` implemented properly (reads all files from workspace/toCompress/, recursively compresses entire directory structure into single .br archive, saves to workspace/compressed/)
- **+10** `decompressDir.js` implemented properly (reads archive.br from workspace/compressed/, decompresses and extracts to workspace/decompressed/, result matches original)

## Advanced Scope

- Worker Threads (src/wt)
- **+10** `worker.js` implemented properly (receives array, returns sorted array)
- **+30** `main.js` implemented properly (reads data.json, splits by CPU count, distributes to workers, k-way merges results)
- Child Processes (src/cp)
- **+10** `execCommand.js` spawns child process from CLI argument
- **+10** child process stdout/stderr piped to parent stdout/stderr
- **+10** parent exits with the same exit code as child

## Forfeits

- **-95% of total task score** Any external tools/libraries are used
- **-30% of total task score** Commits after deadline (except commits that affect only Readme.md, .gitignore, etc.)
Loading