-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (33 loc) · 1.07 KB
/
Copy pathapp.js
File metadata and controls
49 lines (33 loc) · 1.07 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
const path = require('path')
const express = require('express')
const geocode = require('./utils/geocode')
const forecast = require('./utils/forecast')
const app = express()
const publicHtmlPath = path.join(__dirname, './public')
app.use(express.static(publicHtmlPath))
app.get('/weather', (req, res) => {
res.send("Weather")
})
app.get('/products', (req, res) => {
const address = req.query.search
if (!address)
res.send('No search string provided')
else
geocode(address, (error, { latitude, longitude, location }) => {
if (error) {
res.send('The address is not valid')
}
forecast(latitude, longitude, (error, forecastData) => {
if (error) {
res.send('Some error error occured during weather lookup ...')
}
res.send({
Location: location,
Forecast: forecastData
})
})
})
})
app.listen(3000, () => {
console.log('Server is up and running on 3000')
})