├── src ├── streams │ ├── files │ │ ├── fileToWrite.txt │ │ └── fileToRead.txt │ ├── read.js │ ├── write.js │ └── transform.js ├── fs │ ├── files │ │ ├── hello.txt │ │ ├── fileToRemove.txt │ │ ├── dontLookAtMe.txt │ │ ├── fileToRead.txt │ │ └── wrongFilename.txt │ ├── copy.js │ ├── list.js │ ├── read.js │ ├── create.js │ ├── delete.js │ └── rename.js ├── zip │ ├── files │ │ └── fileToCompress.txt │ ├── compress.js │ └── decompress.js ├── hash │ ├── files │ │ └── fileToCalculateHashFor.txt │ └── calcHash.js ├── modules │ ├── files │ │ ├── c.cjs │ │ ├── a.json │ │ └── b.json │ └── cjsToEsm.cjs ├── cli │ ├── env.js │ └── args.js ├── wt │ ├── main.js │ └── worker.js └── cp │ ├── cp.js │ └── files │ └── script.js ├── Readme.md └── package.json /src/streams/files/fileToWrite.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/fs/files/hello.txt: -------------------------------------------------------------------------------- 1 | Hello Node.js -------------------------------------------------------------------------------- /src/fs/files/fileToRemove.txt: -------------------------------------------------------------------------------- 1 | How dare you! -------------------------------------------------------------------------------- /src/zip/files/fileToCompress.txt: -------------------------------------------------------------------------------- 1 | Compress me! -------------------------------------------------------------------------------- /src/fs/files/dontLookAtMe.txt: -------------------------------------------------------------------------------- 1 | What are you looking at?! -------------------------------------------------------------------------------- /src/hash/files/fileToCalculateHashFor.txt: -------------------------------------------------------------------------------- 1 | Calculate hash for me! -------------------------------------------------------------------------------- /src/modules/files/c.cjs: -------------------------------------------------------------------------------- 1 | console.log('Hello from c.cjs!'); 2 | -------------------------------------------------------------------------------- /src/modules/files/a.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": 1, 3 | "b": 2, 4 | "c": 3 5 | } 6 | -------------------------------------------------------------------------------- /src/streams/files/fileToRead.txt: -------------------------------------------------------------------------------- 1 | This file should be read using Streams API -------------------------------------------------------------------------------- /src/modules/files/b.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": 11, 3 | "b": 22, 4 | "c": 33 5 | } 6 | -------------------------------------------------------------------------------- /src/fs/files/fileToRead.txt: -------------------------------------------------------------------------------- 1 | My content 2 | should 3 | be 4 | printed 5 | into 6 | console 7 | ! -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Node.js basics 2 | 3 | ## !!! Please don't submit Pull Requests to this repository !!! 4 | -------------------------------------------------------------------------------- /src/cli/env.js: -------------------------------------------------------------------------------- 1 | const parseEnv = () => { 2 | // Write your code here 3 | }; 4 | 5 | parseEnv(); 6 | -------------------------------------------------------------------------------- /src/fs/files/wrongFilename.txt: -------------------------------------------------------------------------------- 1 | # This is a file with a wrong filename 2 | 3 | Hello from **markdown**! -------------------------------------------------------------------------------- /src/cli/args.js: -------------------------------------------------------------------------------- 1 | const parseArgs = () => { 2 | // Write your code here 3 | }; 4 | 5 | parseArgs(); 6 | -------------------------------------------------------------------------------- /src/fs/copy.js: -------------------------------------------------------------------------------- 1 | const copy = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await copy(); 6 | -------------------------------------------------------------------------------- /src/fs/list.js: -------------------------------------------------------------------------------- 1 | const list = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await list(); 6 | -------------------------------------------------------------------------------- /src/fs/read.js: -------------------------------------------------------------------------------- 1 | const read = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await read(); 6 | -------------------------------------------------------------------------------- /src/fs/create.js: -------------------------------------------------------------------------------- 1 | const create = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await create(); 6 | -------------------------------------------------------------------------------- /src/fs/delete.js: -------------------------------------------------------------------------------- 1 | const remove = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await remove(); 6 | -------------------------------------------------------------------------------- /src/fs/rename.js: -------------------------------------------------------------------------------- 1 | const rename = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await rename(); 6 | -------------------------------------------------------------------------------- /src/streams/read.js: -------------------------------------------------------------------------------- 1 | const read = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await read(); 6 | -------------------------------------------------------------------------------- /src/streams/write.js: -------------------------------------------------------------------------------- 1 | const write = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await write(); 6 | -------------------------------------------------------------------------------- /src/zip/compress.js: -------------------------------------------------------------------------------- 1 | const compress = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await compress(); 6 | -------------------------------------------------------------------------------- /src/streams/transform.js: -------------------------------------------------------------------------------- 1 | const transform = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await transform(); 6 | -------------------------------------------------------------------------------- /src/zip/decompress.js: -------------------------------------------------------------------------------- 1 | const decompress = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await decompress(); 6 | -------------------------------------------------------------------------------- /src/hash/calcHash.js: -------------------------------------------------------------------------------- 1 | const calculateHash = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await calculateHash(); 6 | -------------------------------------------------------------------------------- /src/wt/main.js: -------------------------------------------------------------------------------- 1 | const performCalculations = async () => { 2 | // Write your code here 3 | }; 4 | 5 | await performCalculations(); 6 | -------------------------------------------------------------------------------- /src/cp/cp.js: -------------------------------------------------------------------------------- 1 | const spawnChildProcess = async (args) => { 2 | // Write your code here 3 | }; 4 | 5 | // Put your arguments in function call to test this functionality 6 | spawnChildProcess( /* [someArgument1, someArgument2, ...] */); 7 | -------------------------------------------------------------------------------- /src/wt/worker.js: -------------------------------------------------------------------------------- 1 | // n should be received from main thread 2 | const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); 3 | 4 | const sendResult = () => { 5 | // This function sends result of nthFibonacci computations to main thread 6 | }; 7 | 8 | sendResult(); 9 | -------------------------------------------------------------------------------- /src/cp/files/script.js: -------------------------------------------------------------------------------- 1 | import { EOL } from 'node:os'; 2 | import { argv, stdout, stdin, exit } from 'node:process'; 3 | 4 | const args = argv.slice(2); 5 | 6 | console.log(`Total number of arguments is ${args.length}`); 7 | console.log(`Arguments: ${JSON.stringify(args)}${EOL}`); 8 | 9 | const echoInput = (chunk) => { 10 | const chunkStringified = chunk.toString(); 11 | 12 | if (chunkStringified.includes('CLOSE')) { 13 | exit(0); 14 | } 15 | 16 | stdout.write(`Received from master process: ${chunk.toString()}${EOL}`); 17 | }; 18 | 19 | stdin.on('data', echoInput); 20 | -------------------------------------------------------------------------------- /src/modules/cjsToEsm.cjs: -------------------------------------------------------------------------------- 1 | const path = require('node:path'); 2 | const { release, version } = require('node:os'); 3 | const { createServer: createServerHttp } = require('node:http'); 4 | 5 | require('./files/c.cjs'); 6 | 7 | const random = Math.random(); 8 | 9 | const unknownObject = random > 0.5 ? require('./files/a.json') : require('./files/b.json'); 10 | 11 | console.log(`Release ${release()}`); 12 | console.log(`Version ${version()}`); 13 | console.log(`Path segment separator is "${path.sep}"`); 14 | 15 | console.log(`Path to current file is ${__filename}`); 16 | console.log(`Path to current directory is ${__dirname}`); 17 | 18 | const myServer = createServerHttp((_, res) => { 19 | res.end('Request accepted'); 20 | }); 21 | 22 | const PORT = 3000; 23 | 24 | console.log(unknownObject); 25 | 26 | myServer.listen(PORT, () => { 27 | console.log(`Server is listening on port ${PORT}`); 28 | console.log('To terminate it, use Ctrl+C combination'); 29 | }); 30 | 31 | module.exports = { 32 | unknownObject, 33 | myServer, 34 | }; 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-nodejs-basics", 3 | "version": "1.0.0", 4 | "description": "This repository is the part of nodejs-assignments https://github.com/AlreadyBored/nodejs-assignments", 5 | "engines": { 6 | "node": ">=24.10.0", 7 | "npm": ">=10.9.2" 8 | }, 9 | "type": "module", 10 | "scripts": { 11 | "cli:args": "node src/cli/args.js --some-arg value1 --other 1337 --arg2 42", 12 | "cli:env": "npx cross-env SOME=any RSS_foo=bar RSS_bar=baz node src/cli/env.js", 13 | "cp": "node src/cp/cp.js", 14 | "fs:copy": "node src/fs/copy.js", 15 | "fs:create": "node src/fs/create.js", 16 | "fs:delete": "node src/fs/delete.js", 17 | "fs:list": "node src/fs/list.js", 18 | "fs:read": "node src/fs/read.js", 19 | "fs:rename": "node src/fs/rename.js", 20 | "hash": "node src/hash/calcHash.js", 21 | "modules": "node src/modules/esm.mjs", 22 | "streams:read": "node src/streams/read.js", 23 | "streams:transform": "node src/streams/transform.js", 24 | "streams:write": "node src/streams/write.js", 25 | "wt": "node src/wt/main.js", 26 | "zip:compress": "node src/zip/compress.js", 27 | "zip:decompress": "node src/zip/decompress.js" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/AlreadyBored/node-nodejs-basics.git" 32 | }, 33 | "keywords": [ 34 | "nodejs", 35 | "assignments", 36 | "alreadybored" 37 | ], 38 | "author": "alreadybored", 39 | "license": "ISC", 40 | "bugs": { 41 | "url": "https://github.com/AlreadyBored/node-nodejs-basics/issues" 42 | }, 43 | "homepage": "https://github.com/AlreadyBored/node-nodejs-basics#readme" 44 | } 45 | --------------------------------------------------------------------------------