Skip to content

Commit 1d13325

Browse files
committed
the weather here final version
1 parent e41096c commit 1d13325

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

module3/the_weather_here/.env_sample

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_KEY=YOUR_API_KEY_HERE

module3/the_weather_here/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
node_modules/
3+
database.db

module3/the_weather_here/index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const express = require('express');
22
const Datastore = require('nedb');
33
const fetch = require('node-fetch');
4+
require('dotenv').config();
45

56
const app = express();
6-
app.listen(3000, () =>
7-
console.log('Starting server: http://localhost:3000')
8-
);
7+
const port = process.env.PORT || 3000;
8+
app.listen(port, () => {
9+
console.log(`Starting server at ${port}`);
10+
});
911
app.use(express.static('public'));
1012
app.use(express.json({ limit: '1mb' }));
1113

@@ -37,7 +39,8 @@ app.get('/weather/:latlon', async (request, response) => {
3739
const lat = latlon[0];
3840
const lon = latlon[1];
3941
console.log(lat, lon);
40-
const weather_url = `https://api.darksky.net/forecast/08fe01a78943266193fc7a23625f68fa/${lat},${lon}/?units=si`;
42+
const api_key = process.env.API_KEY;
43+
const weather_url = `https://api.darksky.net/forecast/${api_key}/${lat},${lon}/?units=si`;
4144
const weather_response = await fetch(weather_url);
4245
const weather_data = await weather_response.json();
4346

module3/the_weather_here/package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

module3/the_weather_here/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "This is a version of 'weather here' app by Joey Lee.",
55
"main": "index.js",
66
"scripts": {
7+
"start": "node index.js",
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},
910
"keywords": [
@@ -14,6 +15,7 @@
1415
"author": "Daniel Shiffman",
1516
"license": "MIT",
1617
"dependencies": {
18+
"dotenv": "^8.0.0",
1719
"express": "^4.16.4",
1820
"nedb": "^1.8.0",
1921
"node-fetch": "^2.6.0"

module3/the_weather_here/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<title>The Weather Here</title>
1212
</head>
1313
<body>
14-
<h1>The Weather Here</h1>
14+
<h1>The Weather is Here</h1>
1515
<div>
1616
<a href="/">check in</a> | <a href="/checkins">view checkins</a>
1717
</div>

0 commit comments

Comments
 (0)