-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (39 loc) · 935 Bytes
/
server.js
File metadata and controls
47 lines (39 loc) · 935 Bytes
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
// @ts-check
const { Client } = require("pg");
const express = require("express");
const app = express();
const port = 8080;
const client = new Client({
password: "root",
user: "root",
host: "postgres",
});
app.use(express.static("public"));
app.get("/employees", async (req, res) => {
const results = await client
.query("SELECT * FROM employees")
.then((payload) => {
return payload.rows;
})
.catch(() => {
throw new Error("Query failed");
});
res.setHeader("Content-Type", "application/json");
res.status(200);
res.send(JSON.stringify(results));
});
(async () => {
await client.connect();
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
})();
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("foo");
}, 300);
reject("oops");
});
myPromise.then(() => {
console.log("hello");
});