-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextra-content.js
More file actions
80 lines (64 loc) · 1.99 KB
/
Copy pathextra-content.js
File metadata and controls
80 lines (64 loc) · 1.99 KB
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
const http = require('http');
const fileManager = require("./modules/fileStream");
const {useEffect} = require("react");
const server = http.createServer((req, res) => {
const data = [
{
name: 'A Song of Ice and Fire',
genre: 'Fantasy',
author: 'George R R Martin',
},
{
name: 'The Wheel of Time',
genre: 'Fantasy',
author: 'Robert Jordan',
},
{
name: 'Wings of Fire',
genre: 'Autobiography',
author: 'A P J Abdul Kalam',
}
];
if(req.url === '/') {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(data));
}
else if (req.url === '/autobigraphy') {
res.writeHead(200, {'Content-Type': 'application/json'});
const output = data.filter(function (element) {
return element.genre === 'Autobiography';
});
console.log(output);
res.end(JSON.stringify(output));
}
});
server.listen(PORT, () => {
console.log("Server running in Port 3000");
})
fileManager.syncFileContent('./dataFile.txt');
fileManager.asyncFileContent('./dataFile.txt');
fileManager.syncWriteContent('./syncWriteFile', 'Synchronous File Write');
fileManager.asyncWriteContent('./asyncWriteFile', 'ASynchronous Writing of File');
console.log(data);
import { useState, useEffect } from 'react';
const [counter, setCounter] = useState(0);
const [counterContent, setCounterContent] = useState('Counter: ');
const increaseCounter = () => {
setCounter(counter + 1);
}
const decreaseCounter = () => {
setCounter(counter - 1);
}
useEffect(() => {
if(counter>=10) {
setCounterContent('Wow, the counter is now ');
}
});
useEffect(() => {
setTimeout(() => {
setCounter(counter + 1);
}, 1000);
}, );
<button onClick={increaseCounter}> Click to increase </button>
<button onClick={decreaseCounter}> Click to decrease </button>
<h1>{counterContent} {counter}</h1>