diff --git a/package.json b/package.json index 61220743f3..3108c6c969 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,10 @@ "name": "node-nodejs-basics", "version": "1.0.0", "description": "This repository is the part of nodejs-assignments https://github.com/AlreadyBored/nodejs-assignments", + "engines": { + "node": ">=24.10.0", + "npm": ">=10.9.2" + }, "type": "module", "scripts": { "cli:args": "node src/cli/args.js --some-arg value1 --other 1337 --arg2 42", diff --git a/src/cli/args.js b/src/cli/args.js index 8283f7f7aa..9e3622f791 100644 --- a/src/cli/args.js +++ b/src/cli/args.js @@ -1,5 +1,5 @@ const parseArgs = () => { - // Write your code here + // Write your code here }; -parseArgs(); \ No newline at end of file +parseArgs(); diff --git a/src/cli/env.js b/src/cli/env.js index fe4aa4a8df..e3616dc8e7 100644 --- a/src/cli/env.js +++ b/src/cli/env.js @@ -1,5 +1,5 @@ const parseEnv = () => { - // Write your code here + // Write your code here }; -parseEnv(); \ No newline at end of file +parseEnv(); diff --git a/src/cp/cp.js b/src/cp/cp.js index 4a87b98c55..72c6addc9c 100644 --- a/src/cp/cp.js +++ b/src/cp/cp.js @@ -1,5 +1,5 @@ const spawnChildProcess = async (args) => { - // Write your code here + // Write your code here }; // Put your arguments in function call to test this functionality diff --git a/src/cp/files/script.js b/src/cp/files/script.js index 44a0622fbc..0c6654f12f 100644 --- a/src/cp/files/script.js +++ b/src/cp/files/script.js @@ -1,12 +1,19 @@ -const args = process.argv.slice(2); +import { EOL } from 'node:os'; +import { argv, stdout, stdin, exit } from 'node:process'; + +const args = argv.slice(2); console.log(`Total number of arguments is ${args.length}`); -console.log(`Arguments: ${JSON.stringify(args)}`); +console.log(`Arguments: ${JSON.stringify(args)}${EOL}`); const echoInput = (chunk) => { - const chunkStringified = chunk.toString(); - if (chunkStringified.includes('CLOSE')) process.exit(0); - process.stdout.write(`Received from master process: ${chunk.toString()}\n`) + const chunkStringified = chunk.toString(); + + if (chunkStringified.includes('CLOSE')) { + exit(0); + } + + stdout.write(`Received from master process: ${chunk.toString()}${EOL}`); }; -process.stdin.on('data', echoInput); +stdin.on('data', echoInput); diff --git a/src/fs/copy.js b/src/fs/copy.js index bd17fe3991..e226075b4c 100644 --- a/src/fs/copy.js +++ b/src/fs/copy.js @@ -1,5 +1,5 @@ const copy = async () => { - // Write your code here + // Write your code here }; await copy(); diff --git a/src/fs/create.js b/src/fs/create.js index 8d18cf9fc2..6ede285599 100644 --- a/src/fs/create.js +++ b/src/fs/create.js @@ -1,5 +1,5 @@ const create = async () => { - // Write your code here + // Write your code here }; -await create(); \ No newline at end of file +await create(); diff --git a/src/fs/delete.js b/src/fs/delete.js index 4718dbc4c5..a70b13766c 100644 --- a/src/fs/delete.js +++ b/src/fs/delete.js @@ -1,5 +1,5 @@ const remove = async () => { - // Write your code here + // Write your code here }; -await remove(); \ No newline at end of file +await remove(); diff --git a/src/fs/list.js b/src/fs/list.js index c0a83dea15..0c0fa21f7e 100644 --- a/src/fs/list.js +++ b/src/fs/list.js @@ -1,5 +1,5 @@ const list = async () => { - // Write your code here + // Write your code here }; -await list(); \ No newline at end of file +await list(); diff --git a/src/fs/read.js b/src/fs/read.js index 52c78cc6ee..e3938be563 100644 --- a/src/fs/read.js +++ b/src/fs/read.js @@ -1,5 +1,5 @@ const read = async () => { - // Write your code here + // Write your code here }; -await read(); \ No newline at end of file +await read(); diff --git a/src/fs/rename.js b/src/fs/rename.js index 2bb99ecdb5..b1d65b0c86 100644 --- a/src/fs/rename.js +++ b/src/fs/rename.js @@ -1,5 +1,5 @@ const rename = async () => { - // Write your code here + // Write your code here }; -await rename(); \ No newline at end of file +await rename(); diff --git a/src/hash/calcHash.js b/src/hash/calcHash.js index 450f8f72e2..e37c17ed62 100644 --- a/src/hash/calcHash.js +++ b/src/hash/calcHash.js @@ -1,5 +1,5 @@ const calculateHash = async () => { - // Write your code here + // Write your code here }; -await calculateHash(); \ No newline at end of file +await calculateHash(); diff --git a/src/modules/cjsToEsm.cjs b/src/modules/cjsToEsm.cjs index 8b7be2a48b..089bd2db13 100644 --- a/src/modules/cjsToEsm.cjs +++ b/src/modules/cjsToEsm.cjs @@ -1,17 +1,12 @@ -const path = require('path'); -const { release, version } = require('os'); -const { createServer: createServerHttp } = require('http'); -require('./files/c'); +const path = require('node:path'); +const { release, version } = require('node:os'); +const { createServer: createServerHttp } = require('node:http'); -const random = Math.random(); +require('./files/c.cjs'); -let unknownObject; +const random = Math.random(); -if (random > 0.5) { - unknownObject = require('./files/a.json'); -} else { - unknownObject = require('./files/b.json'); -} +const unknownObject = random > 0.5 ? require('./files/a.json') : require('./files/b.json'); console.log(`Release ${release()}`); console.log(`Version ${version()}`); @@ -21,7 +16,7 @@ console.log(`Path to current file is ${__filename}`); console.log(`Path to current directory is ${__dirname}`); const myServer = createServerHttp((_, res) => { - res.end('Request accepted'); + res.end('Request accepted'); }); const PORT = 3000; @@ -29,12 +24,11 @@ const PORT = 3000; console.log(unknownObject); myServer.listen(PORT, () => { - console.log(`Server is listening on port ${PORT}`); - console.log('To terminate it, use Ctrl+C combination'); + console.log(`Server is listening on port ${PORT}`); + console.log('To terminate it, use Ctrl+C combination'); }); module.exports = { - unknownObject, - myServer, + unknownObject, + myServer, }; - diff --git a/src/modules/files/a.json b/src/modules/files/a.json index 7878a209f6..d1f6dac48a 100644 --- a/src/modules/files/a.json +++ b/src/modules/files/a.json @@ -1,5 +1,5 @@ { - "a": 1, - "b": 2, - "c": 3 -} \ No newline at end of file + "a": 1, + "b": 2, + "c": 3 +} diff --git a/src/modules/files/b.json b/src/modules/files/b.json index 5214b8c93d..e442128649 100644 --- a/src/modules/files/b.json +++ b/src/modules/files/b.json @@ -1,5 +1,5 @@ { - "a": 11, - "b": 22, - "c": 33 -} \ No newline at end of file + "a": 11, + "b": 22, + "c": 33 +} diff --git a/src/modules/files/c.cjs b/src/modules/files/c.cjs new file mode 100644 index 0000000000..df728e1627 --- /dev/null +++ b/src/modules/files/c.cjs @@ -0,0 +1 @@ +console.log('Hello from c.cjs!'); diff --git a/src/modules/files/c.js b/src/modules/files/c.js deleted file mode 100644 index ac09fab173..0000000000 --- a/src/modules/files/c.js +++ /dev/null @@ -1 +0,0 @@ -console.log('Hello from c.js!'); \ No newline at end of file diff --git a/src/streams/read.js b/src/streams/read.js index 52c78cc6ee..e3938be563 100644 --- a/src/streams/read.js +++ b/src/streams/read.js @@ -1,5 +1,5 @@ const read = async () => { - // Write your code here + // Write your code here }; -await read(); \ No newline at end of file +await read(); diff --git a/src/streams/transform.js b/src/streams/transform.js index 315fc6597f..9e6c15fe84 100644 --- a/src/streams/transform.js +++ b/src/streams/transform.js @@ -1,5 +1,5 @@ const transform = async () => { - // Write your code here + // Write your code here }; -await transform(); \ No newline at end of file +await transform(); diff --git a/src/streams/write.js b/src/streams/write.js index fc917160a2..84aa11e7cb 100644 --- a/src/streams/write.js +++ b/src/streams/write.js @@ -1,5 +1,5 @@ const write = async () => { - // Write your code here + // Write your code here }; -await write(); \ No newline at end of file +await write(); diff --git a/src/wt/main.js b/src/wt/main.js index 37d80484ec..e2ef054d41 100644 --- a/src/wt/main.js +++ b/src/wt/main.js @@ -1,5 +1,5 @@ const performCalculations = async () => { - // Write your code here + // Write your code here }; -await performCalculations(); \ No newline at end of file +await performCalculations(); diff --git a/src/wt/worker.js b/src/wt/worker.js index 441b2154f8..405595394d 100644 --- a/src/wt/worker.js +++ b/src/wt/worker.js @@ -2,7 +2,7 @@ const nthFibonacci = (n) => n < 2 ? n : nthFibonacci(n - 1) + nthFibonacci(n - 2); const sendResult = () => { - // This function sends result of nthFibonacci computations to main thread + // This function sends result of nthFibonacci computations to main thread }; -sendResult(); \ No newline at end of file +sendResult(); diff --git a/src/zip/compress.js b/src/zip/compress.js index bb328f43c6..d55209587e 100644 --- a/src/zip/compress.js +++ b/src/zip/compress.js @@ -1,5 +1,5 @@ const compress = async () => { - // Write your code here + // Write your code here }; -await compress(); \ No newline at end of file +await compress(); diff --git a/src/zip/decompress.js b/src/zip/decompress.js index 69f6c345f8..8aaf26c8a4 100644 --- a/src/zip/decompress.js +++ b/src/zip/decompress.js @@ -1,5 +1,5 @@ const decompress = async () => { - // Write your code here + // Write your code here }; -await decompress(); \ No newline at end of file +await decompress();