Skip to content
Merged
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/cli/args.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const parseArgs = () => {
// Write your code here
// Write your code here
};

parseArgs();
parseArgs();
4 changes: 2 additions & 2 deletions src/cli/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const parseEnv = () => {
// Write your code here
// Write your code here
};

parseEnv();
parseEnv();
2 changes: 1 addition & 1 deletion src/cp/cp.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 13 additions & 6 deletions src/cp/files/script.js
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion src/fs/copy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const copy = async () => {
// Write your code here
// Write your code here
};

await copy();
4 changes: 2 additions & 2 deletions src/fs/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const create = async () => {
// Write your code here
// Write your code here
};

await create();
await create();
4 changes: 2 additions & 2 deletions src/fs/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const remove = async () => {
// Write your code here
// Write your code here
};

await remove();
await remove();
4 changes: 2 additions & 2 deletions src/fs/list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const list = async () => {
// Write your code here
// Write your code here
};

await list();
await list();
4 changes: 2 additions & 2 deletions src/fs/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const read = async () => {
// Write your code here
// Write your code here
};

await read();
await read();
4 changes: 2 additions & 2 deletions src/fs/rename.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const rename = async () => {
// Write your code here
// Write your code here
};

await rename();
await rename();
4 changes: 2 additions & 2 deletions src/hash/calcHash.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const calculateHash = async () => {
// Write your code here
// Write your code here
};

await calculateHash();
await calculateHash();
28 changes: 11 additions & 17 deletions src/modules/cjsToEsm.cjs
Original file line number Diff line number Diff line change
@@ -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()}`);
Expand All @@ -21,20 +16,19 @@ 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;

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,
};

8 changes: 4 additions & 4 deletions src/modules/files/a.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"a": 1,
"b": 2,
"c": 3
}
"a": 1,
"b": 2,
"c": 3
}
8 changes: 4 additions & 4 deletions src/modules/files/b.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"a": 11,
"b": 22,
"c": 33
}
"a": 11,
"b": 22,
"c": 33
}
1 change: 1 addition & 0 deletions src/modules/files/c.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello from c.cjs!');
1 change: 0 additions & 1 deletion src/modules/files/c.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/streams/read.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const read = async () => {
// Write your code here
// Write your code here
};

await read();
await read();
4 changes: 2 additions & 2 deletions src/streams/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const transform = async () => {
// Write your code here
// Write your code here
};

await transform();
await transform();
4 changes: 2 additions & 2 deletions src/streams/write.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const write = async () => {
// Write your code here
// Write your code here
};

await write();
await write();
4 changes: 2 additions & 2 deletions src/wt/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const performCalculations = async () => {
// Write your code here
// Write your code here
};

await performCalculations();
await performCalculations();
4 changes: 2 additions & 2 deletions src/wt/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
sendResult();
4 changes: 2 additions & 2 deletions src/zip/compress.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const compress = async () => {
// Write your code here
// Write your code here
};

await compress();
await compress();
4 changes: 2 additions & 2 deletions src/zip/decompress.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const decompress = async () => {
// Write your code here
// Write your code here
};

await decompress();
await decompress();