Skip to content

Commit 7978870

Browse files
Add files via upload
0 parents  commit 7978870

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// creatinf a txt file using fs module
2+
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+
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+
});

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "node",
3+
"version": "1.0.0",
4+
"description": "\"my first npm file",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index"
8+
},
9+
"author": "sabha mushtaq",
10+
"license": "ISC"
11+
}

0 commit comments

Comments
 (0)