-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.js
158 lines (89 loc) · 2.62 KB
/
module.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// NPM module
// const color = require('cli-color')
// console.log(color.redBright('Hello Node js'))
// Local module
// const auth = require('./auth')
// auth.register('abhishek')
// auth.login('abhishek kumar','secret')
// Core modules
const path = require('path')
// dirname
// console.log('Folder name: ', path.dirname(__filename))
// filename
// console.log('File name: ', path.basename(__filename))
// Extension
// console.log('Ext name: ', path.extname(__filename))
// parse
// console.log('Parse : ', path.parse(__filename))
// Join
// console.log('Join : ', path.join(__dirname, 'order', 'app.js'))
// File system
const fs = require('fs')
// // Make a directory
// fs.mkdir(path.join(__dirname, '/test'), (err) => {
// if (err) {
// console.log(err)
// return
// }
// console.log('Folder created...')
// })
// Create a file
// fs.writeFile(path.join(__dirname, 'test', 'test.txt'), 'Hello Node\n', (err) => {
// if(err) {
// throw err
// }
// // else{
// // console.log('File created...')
// // }
// fs.appendFile(path.join(__dirname, 'test', 'test.txt'), 'More data', (err) => {
// if(err) {
// throw err
// }
// console.log('Data added...')
// })
// console.log('File created...')
// })
// Read a file
// fs.readFile(path.join(__dirname, 'test', 'test.txt'), 'utf-8', (err, data) => {
// if(err) {
// throw err
// }
// // const content = Buffer.from(data)
// // console.log(content.toString())
// console.log(data)
// })
// Os module
const os = require('os')
// console.log('Os type: ', os.type())
// console.log('Os platform: ', os.platform())
// console.log('Cpu architecture: ', os.arch())
// console.log('Cpu details: ', os.cpus())
// console.log('Free memory : ', os.freemem())
// console.log('Total memory : ', os.totalmem())
// console.log('Uptime : ', os.uptime())
// Events module
const Emitter = require('events')
// const myEmitter = new Emitter()
// myEmitter.on('somename', (data) => {
// console.log(data)
// })
// myEmitter.emit('somename', {
// name: 'Rakesh'
// })
// class Auth extends Emitter{
// register(username) {
// console.log('Registered successfully...')
// this.emit('registered', username)
// }
// }
// const auth = new Auth()
// Listen
// Verify email
// auth.on('registered', (data) =>{
// console.log(`Sending email to ${data}`)
// })
// welcome email
// auth.on('registered', (data) =>{
// console.log(`Sending welcome email to ${data}`)
// })
// auth.register('codersGyan')