Skip to content

Commit b92403a

Browse files
committed
Update configuration
1 parent 15bd0eb commit b92403a

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

.gitpod.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
66

7+
vscode:
8+
extensions:
9+
- "esbenp.prettier-vscode"
10+
711
tasks:
812
- name: Prepare workspace
913
before: pnpm i -g nodemon
1014
init: pnpm install
11-
12-
- name: Start Express server
1315
command: pnpm start

app/app.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,38 @@ const express = require("express");
22
const app = express();
33
const PORT = 3000;
44

5+
function getFileData(response) {
6+
// fs.readFileSync() reads a file. The first parameter is the path to the file, and the second is the encoding.
7+
try {
8+
const data = fs.readFileSync("locations.json", "utf8");
9+
return JSON.parse(data);
10+
} catch (e) {
11+
console.error(e);
12+
response.sendStatus(500);
13+
return;
14+
}
15+
}
16+
17+
function setFileData(fileData, response) {
18+
// fs.writeFile() writes to a file. The first parameter is the path to the file, the second is the data to write,
19+
// and the third is a callback function that takes one parameter: error.
20+
fs.writeFile("locations.json", JSON.stringify(fileData), (error) => {
21+
if (error) {
22+
console.error(error);
23+
response.sendStatus(500);
24+
return;
25+
}
26+
27+
response.sendStatus(200);
28+
});
29+
}
30+
531
// Creates a GET endpoint at the root URL that returns a string
632
app.get("/", function (request, response) {
7-
response.send("Hello, world!");
33+
response.send("Hello, world!");
834
});
935

1036
// Starts the server on port 3000
11-
app.listen(PORT, function() {
12-
console.log(`Server listening on port ${PORT}!`);
37+
app.listen(PORT, function () {
38+
console.log(`Server listening on port ${PORT}!`);
1339
});

0 commit comments

Comments
 (0)