-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-writeme.js
executable file
·30 lines (28 loc) · 1.03 KB
/
1-writeme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/node
/**
* This script writes content to a file.
*
* It uses Node.js built-in modules: 'fs' for file system operations and 'process' for accessing system information.
*
* The script expects two command line arguments (process.argv[2] and process.argv[3]):
* 1. The file path where the content will be written.
* 2. The content to be written to the file.
*
* The 'fs.writeFile' function is used to write the content to the file. It takes four arguments:
* 1. The file path
* 2. The content to be written
* 3. The file encoding ('utf-8' in this case)
* 4. A callback function that is called when the file write operation is complete.
*
* The callback function checks if there was an error during the file write operation.
* If there was an error, it logs the error to the console and returns.
*/
const fs = require('fs');
const process = require('process');
const filePath = process.argv[2];
const content = process.argv[3];
fs.writeFile(filePath, content, 'utf-8', (err, buffer) => {
if (err) {
console.error(err);
}
});