-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileworking.js
61 lines (46 loc) · 1.17 KB
/
fileworking.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//working with file
const fs=require('fs')
fs.writeFile('Main.txt','This is Main.txt',(err)=>{
if (err){
console.log(err);
}
else{
console.log('Successfully created file Main.txt');
fs.readFile('Main.txt', 'utf8',(err,file)=>{
if (err)
console.log(err)
else
console.log(file)
});
}
//rename
fs.rename('Main.txt', 'Mains.txt',(err)=>{
if (err)
console.log(err)
else
console.log('successfully renamed the file!')
})
})
// //node js basic EventEmitter
// const EventEmitter=require('events');
// const eventEmitter=new EventEmitter();
// eventEmitter.on('name',(num1,num2)=>{
// console.log('The add of two number is :' , num1+num2)
// })
// eventEmitter.emit('name',2,3)
// //using class eventEmitter method
// class Person extends EventEmitter {
// constructor(name){
// super();
// this._name=name;
// }
// get name(){
// return this._name;
// }
// }
// let person=new Person('Nabin saud');
// person.on('click',()=>{
// console.log('Your name is ' + person.name);
// })
// //
// person.emit('click');