-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
22 lines (18 loc) · 603 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const express = require("express");
const bodyParser = require("body-parser");
const weatherReq = require("./requests/weather.requests");
const app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.render("index", { weather: null, error: null });
});
app.post("/", async (req, res) => {
const { city } = req.body;
const { weather, error } = await weatherReq(city);
res.render("index", { weather, error });
});
app.listen(3000, () => {
console.log("port:3000");
});