1
0

Video 69: Avoiding Global Modules

Completed weather app, including all updates from Section 9 (Videos 60-69)
This commit is contained in:
Jason Williams 2019-10-10 17:48:22 -06:00
parent 6d75e93eaf
commit 0628f3cdc7
5 changed files with 8 additions and 6 deletions

View File

@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node src/app.js"
},
"keywords": [],
"author": "",

View File

@ -5,6 +5,7 @@ const geocode = require('./utils/geocode')
const forecast = require('./utils/forecast')
const app = express()
const port = process.env.PORT || 4200
// Define paths for Express config
const publicDirectoryPath = path.join(__dirname, '../public')
@ -96,6 +97,6 @@ app.get('*', (req, res) => {
})
})
app.listen(4200, () => {
console.log('Server is up on port 4200.')
app.listen(port, () => {
console.log('Server is up on port ' + port + '.')
})

View File

@ -1,7 +1,7 @@
const request = require('request')
const forecast = (latitude, longitude, callback) => {
const url = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/' + latitude + ',' + longitude + '?units=si'
const url = 'https://api.darksky.net/forecast/bae9e39ba5c00299d5a95b35c1ae20cc/' + latitude + ',' + longitude + '?units=si'
request({ url, json: true }, (error, {body}) => {
if (error) {
@ -9,7 +9,7 @@ const forecast = (latitude, longitude, callback) => {
} else if (body.error) {
callback('Unable to find location', undefined)
} else {
callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. There is a ' + body.currently.precipProbability + '% chance of rain.')
callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. Today\'s high will be ' + body.daily.data[0].temperatureMax + ' degrees, with a low of ' + body.daily.data[0].temperatureMin + '. There is a ' + body.currently.precipProbability + '% chance of rain.')
}
})
}

View File

@ -1,7 +1,7 @@
const request = require('request')
const geocode = (address, callback) => {
const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + encodeURIComponent(address) + '.json?access_token=pk.eyJ1IjoiamF5d2xsIiwiYSI6ImYyZjkyMGNlOTgyNGQ5ZWM5ZDExN2FjNGYwMDZmNTQ4In0.y3lv5ddmGhVNSL7wfMpB0g&limit=1'
const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + encodeURIComponent(address) + '.json?access_token=pk.eyJ1IjoiamFzb24zMmRldiIsImEiOiJjazFsNHd5djcwMXptM2htbW8zM3MyZGxuIn0.-TtNNGFysQPQRfGR1P8DUA&limit=1'
request({ url, json: true }, (error, {body}) => {
if (error) {

View File

@ -11,6 +11,7 @@
<body>
<div class="main-content">
{{>header}}
<p>This site was created by Jason Williams. It uses data from mapbox.com and darksky.net!</p>
<img class="portrait" src="/img/me.jpg">
</div>