|
1 |
| -// creatinf a txt file using fs module |
| 1 | +const os = require("os"); |
| 2 | +let versionos = os.release(); |
| 3 | +console.log("OS RELEASE:",versionos); |
| 4 | +let osname = os.type(); |
| 5 | +console.log("operating system name :",osname); |
2 | 6 |
|
3 |
| -const { log } = require("console"); |
4 |
| -const fs = require("fs"); |
5 |
| -let info = "NodeJS is built on an event-driven architecture, which is fundamental to its asynchronous and non-blocking I/O model. This architecture revolves around the concept of events, event emitters, and event listeners, enabling efficient handling of asynchronous operations and concurrent requests." |
6 |
| -fs.appendFile('node_architecture.txt',info,(err) => { |
7 |
| - if (err) throw err; |
8 |
| - console.log('The "data to append" was appended to file!')} |
9 |
| -); |
10 | 7 |
|
11 |
| -// reading and consoling data from a file on terminal |
12 |
| - |
13 |
| -let pathname = "./node_architecture.txt"; |
14 |
| -fs.readFile(pathname,'utf-8',(err,data)=>{ |
15 |
| -if(err){ |
16 |
| -console.log('error reading the file',err); |
17 |
| -return; |
18 |
| - |
19 |
| -} |
20 |
| -console.log('file content',data); |
21 |
| - |
22 |
| - |
23 |
| -}) |
24 |
| - |
25 |
| -// appending data to the file |
26 |
| - |
27 |
| - |
28 |
| -const appendData = 'Node.js allows programmers to develop server-side JavaScript and frontend JavaScript codes with simplicity. One of the major Node.js advantages is that it eliminates the need for two resource teams, saving time, money, and energy for overall project development.'; |
29 |
| - |
30 |
| -fs.appendFile('node_architecture.txt', appendData, (err) => { |
31 |
| - if (err) { |
32 |
| - console.log("Couldn't append data:", err); |
33 |
| - } else { |
34 |
| - console.log("Content appended successfully to the file"); |
35 |
| - } |
36 |
| -}); |
37 |
| - |
38 |
| -// deleting created file |
39 |
| -fs.unlink('node_architecture.txt', (err) => { |
40 |
| - if (err) { |
41 |
| - console.error("Error deleting the file:", err); |
42 |
| - } else { |
43 |
| - console.log("File deleted successfully!"); |
44 |
| - } |
45 |
| -}); |
0 commit comments