-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding New Files to Weather Forecaster
- Loading branch information
1 parent
76f144b
commit 4a9955c
Showing
8 changed files
with
1,382 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const request = require('request'); | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const app = express(); | ||
app.use(bodyParser.urlencoded({extended: true})); | ||
app.get('/', (req, res) => { | ||
res.render('form.ejs') | ||
}); | ||
app.post('/result', (req, res) => { | ||
const url = 'http://api.weatherstack.com/current?access_key=' + process.env.API_KEY + '&query=' + req.body.query; | ||
request({url: url, json: true}, (error, response) => { | ||
if(error){ | ||
res.render('nointernet.ejs') | ||
}else if(response.body.error){ | ||
res.render('notfound.ejs') | ||
}else{ | ||
// const query = data.request.type + ': ' + data.location.name + ", " + data.location.region + ' - ' + data.location.country + ', Temperture: ' + data.current.temperature + "° - " + data.current.weather_descriptions + ", Humidity: " + data.current.humidity + ', Wind Direction: ' + data.current.wind_dir + ',\n' + "Is Day: " + data.current.is_day + ', UV_Index: ' + data.current.uv_index + ", Pressure: " + data.current.pressure + | ||
// ', Precipitation: ' + data.current.precip + ', Wind Speed: ' + data.current.wind_speed + ", Wind Degree: " + data.current.wind_degree + '°' | ||
res.render('result.ejs', {query: response.body}); | ||
} | ||
}); | ||
}); | ||
app.get("*", (req, res)=>{ | ||
res.render('404.ejs') | ||
}) | ||
app.listen(process.env.PORT || 4000, process.env.IP, () => { | ||
console.log('SERVER HAS STARTED!!!'); | ||
}) |
Oops, something went wrong.