Skip to content

Commit 89108f4

Browse files
committed
Section 24: Accessing Standard Library Modules
1 parent 8ccee56 commit 89108f4

5 files changed

Lines changed: 96 additions & 19 deletions

File tree

24-Create-Node-JS-Command-Line-Tools/01-/index.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

24-Create-Node-JS-Command-Line-Tools/01-/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

24-Create-Node-JS-Command-Line-Tools/01-watchit/index.html

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const fs = require('fs')
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
## 24-Create-Node-JS-Command-Line-Tools
2+
3+
**folder 01**
4+
5+
## 1. 03 Working with Modules
6+
7+
## 2. 04 Invisible Node Functions
8+
9+
```javascript
10+
// in index.js
11+
console.log(arguments)
12+
```
13+
14+
This prints out the arguments huge object to the console
15+
16+
```json
17+
[Arguments] {
18+
...
19+
}
20+
```
21+
22+
```javascript
23+
// in index.js
24+
console.log(arguments)
25+
console.log(require)
26+
console.log(module)
27+
console.log(__filename)
28+
console.log(__dirname)
29+
```
30+
31+
## 3. 05 The Require Cache
32+
33+
```javascript
34+
// in index.js
35+
require('./myscript.js')
36+
console.log(require.cache)
37+
38+
// in myscript.js
39+
const message = 'hello world'
40+
41+
module.exports = message
42+
```
43+
44+
## 4. 06 Files Get Required Once
45+
46+
```javascript
47+
// in index.js
48+
const counterObject = require('./myscript.js')
49+
50+
console.log(counterObject.getCounter())
51+
counterObject.incrementCounter()
52+
console.table(counterObject.getCounter())
53+
54+
const newCounterObject = require('./myscript.js')
55+
console.log(newCounterObject.getCounter())
56+
57+
// in myscript.js
58+
let counter = 0
59+
60+
module.exports = {
61+
incrementCounter() {
62+
counter = counter + 1
63+
},
64+
getCounter() {
65+
return counter
66+
},
67+
}
68+
```
69+
70+
## 5. 07 Debugging with Node
71+
72+
`node inspect index.js`
73+
74+
#### CLI Debugger Commands
75+
76+
- c => Continue execution until program ends or next debugger statement
77+
- n => Run the next line of code
78+
- s => Step in to a function
79+
- o => Step out of the current function
80+
81+
**After entering the debu> we can open the repl console by typing repl in the debugger**
82+
83+
`node inspect index.js` => Start up a debugger **CLI** and pause execution whenever a 'debugger' statement is hit
84+
85+
`node --inspect index.js` => Start up a debugger instance and pause execution whenever a 'debugger' statement is hit. Access the debugger at '**chrome://inspect'**
86+
87+
`node --inspect-brk index.js` => Start up a debugger instance and wait to execute until a debugger is connected. Access the debugger at '**chrome://inspect'**
88+
89+
## 6. 09 Accessing Standard Library Modules
90+
91+
**folder 01**
92+
93+
NodeJS documentation https://nodejs.org/
94+
95+
https://nodejs.org/dist/latest-v18.x/docs/api/fs.html

0 commit comments

Comments
 (0)