-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (28 loc) · 1 KB
/
server.js
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
const express = require("express");
const app = express();
const port = process.env.PORT || 3000;
const { fork } = require("child_process");
app.use(express.static("public"));
app.use(express.json());
app.listen(port);
app.get("/allTimeZones", (_request, response) => {
let childProcess = fork("./child-processes/all-Time-Zones.js");
childProcess.on("message", (allTimeZoneData) =>
response.send(allTimeZoneData)
);
});
app.get("/city", (request, response) => {
let childProcess = fork("./child-processes/time-for-one-city.js");
childProcess.send({ cityName: request.query.cityName });
childProcess.on("message", (timeForCity) => response.send(timeForCity));
});
app.post("/nextNhoursWeather", (request, response) => {
let childProcess = fork("./child-processes/next-N-Hours-Weather.js");
childProcess.send({
cityDateTimeName: request.body.city_Date_Time_Name,
hours: request.body.hours,
});
childProcess.on("message", (nextNhoursWeather) =>
response.send(nextNhoursWeather)
);
});