Skip to content

Commit 7915ff7

Browse files
committed
create ECMAScript Module
1 parent d601d3d commit 7915ff7

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// To execute ECMAScript Module import/export standards, the file convention should be .mjs instead of .js
2+
// & it should be explicitly runned as > node httpsECMA.mjs
3+
4+
import { send, REQUEST_TIMEOUT } from "./requestECMA.mjs";
5+
import { read } from "./responseECMA.mjs";
6+
7+
function makeRequest(url, data) {
8+
send(url, data);
9+
return read();
10+
}
11+
12+
const responseData = makeRequest("https:www.google.com", "Hello");
13+
14+
setTimeout(() => {
15+
console.log(responseData);
16+
}, REQUEST_TIMEOUT);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const REQUEST_TIMEOUT = 500;
2+
3+
function encrypt(data) {
4+
return "encrypted data";
5+
}
6+
7+
function send(url, data) {
8+
const encryptedData = encrypt(data);
9+
console.log(`Sending ${encryptedData} to ${url}`);
10+
}
11+
12+
// ECMAScript module standards
13+
export { send, REQUEST_TIMEOUT };
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function decrypt(data) {
2+
return "decrypted data";
3+
}
4+
5+
function read() {
6+
return decrypt("data");
7+
}
8+
9+
// ECMAScript module standards
10+
export { read };

0 commit comments

Comments
 (0)