Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (59 loc) · 1.34 KB
/
Copy pathapp.js
File metadata and controls
71 lines (59 loc) · 1.34 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
const express = require("express");
const { Client } = require("pg");
var connectionString = "postgres://postgres:postgres@localhost:5432/jordan";
const client = new Client({
connectionString: connectionString,
});
client.connect();
const app = express();
app.get("/", (req, res) => {
res.send("server is working...");
});
app.get("/get-from-db", (req, res) => {
client.query("SELECT * FROM data", (err, result) => {
if (err) {
console.log(err);
} else {
res.send({
data: result.rows,
});
}
});
});
app.get("/write-to-db", (req, res) => {
client.query("INSERT INTO data VALUES (888)", (err, result) => {
if (err) {
console.log(err);
} else {
res.send({
data: result.rows,
});
}
});
});
app.get("/math-test", (req, res) => {
const limit = 10 * 10 ** 8;
let numerator = 0;
let denominator = 1;
let result = 0;
for (let i = 0; i < limit; i++) {
result += numerator++ / denominator++;
}
res.send({ value: result });
});
app.get("/simple-math", (req, res) => {
let a = 999;
let b = 888;
let c = 777;
res.send({ value: (a * b) / c });
});
app.get("/get-from-api", (req, res) => {
fetch("https://httpbin.org/get")
.then((res) => {
return res.json();
})
.then((data) => {
res.send({ data: data });
});
});
app.listen("3000");