File tree 3 files changed +94
-0
lines changed 3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+
3
+ require by default look for these extensions chronologically -
4
+ 1. '.js'
5
+ 2. '.json'
6
+ 3. '.node'
7
+
8
+ */
9
+
10
+ const { send } = require ( "./request" ) ; // ES6 destructuring
11
+ const { read } = require ( "./response" ) ;
12
+
13
+ /*
14
+
15
+ Just another way of doing same thing ↓
16
+
17
+ const response = require('./response')
18
+ const request = require('./request')
19
+
20
+ response.send()
21
+ request.read()
22
+
23
+
24
+ */
25
+
26
+ function makeRequest ( url , data ) {
27
+ send ( url , data ) ;
28
+ return read ( ) ;
29
+ }
30
+
31
+ const responseData = makeRequest ( "https:www.google.com" , "Hello" ) ;
32
+ console . log ( responseData ) ;
Original file line number Diff line number Diff line change
1
+ function encrypt ( data ) {
2
+ return "encrypted data" ;
3
+ }
4
+
5
+ function send ( url , data ) {
6
+ const encryptedData = encrypt ( data ) ;
7
+ console . log ( `Sending ${ encryptedData } to ${ url } ` ) ;
8
+ }
9
+
10
+ module . exports = {
11
+ // send: send
12
+ // requestSend: send, // if exporting function with different name
13
+ send, // if exporting function with same name
14
+ } ;
15
+
16
+ console . log ( module ) ;
17
+
18
+ /*
19
+
20
+ if,
21
+
22
+ module.exports = {
23
+ requestSend: send
24
+ }
25
+
26
+ then,
27
+
28
+ const { requestSend } = require(request)
29
+
30
+ */
Original file line number Diff line number Diff line change
1
+ function decrypt ( data ) {
2
+ return "decrypted data" ;
3
+ }
4
+
5
+ function read ( ) {
6
+ return decrypt ( "data" ) ;
7
+ }
8
+
9
+ module . exports = {
10
+ // read: read
11
+ read,
12
+ } ;
13
+
14
+ /*
15
+
16
+ Few other ways ↓
17
+
18
+ module.exports.read = read // If exporting function with same name
19
+ module.exports.requestRead = read // If exporting function with different name
20
+
21
+ or directly,
22
+
23
+ exports.read = read
24
+ exports.requestRead = read
25
+
26
+ or even better,
27
+
28
+ exports.read() {
29
+ return decrypt("data")
30
+ }
31
+
32
+ */
You can’t perform that action at this time.
0 commit comments