-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 1.16 KB
/
index.js
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
/*
Приложение которое показывает погоду по городу ульяновску
@airoo
*/
const express = require('express')
const rp = require('request-promise')
const exphbs = require('express-handlebars')
const app = express()
var path = require("path");
app.engine('.hbs', exphbs({
defaultLayout: 'main',
extname: '.hbs',
layoutsDir: path.join(__dirname, 'views/layouts')
}))
app.set('view engine', '.hbs')
app.set('views', path.join(__dirname, 'views'))
app.get('/city', (req, res) => {
rp({
uri: 'http://apidev.accuweather.com/currentconditions/v1/296217',
qs: {
language: 'ru',
apiKey: 'hoArfRosT1215'
// Используйте ваш ключ для accuweather API
},
json: true
})
.then((data) => {
//console.log(data[0]['Temperature']['Metric']['Value'])
res.render('index', {
data: data,
WeatherText: data[0]['WeatherText'],
temperature: data[0]['Temperature']['Metric']['Value']
})
})
.catch((err) => {
console.log(err)
res.render('error')
})
})
app.listen(3000)