-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (23 loc) · 784 Bytes
/
app.js
File metadata and controls
29 lines (23 loc) · 784 Bytes
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
const express = require("express");
const weather = require("weather-js");
const bodyParser = require('body-parser');
const path = require("path");
const app = express();
app.use( bodyParser.json() );
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname + '/public')));
app.get('/',(req,res) => {
res.render('pages/home.ejs');
});
app.post('/weather',(req,res) => {
weather.find({search: req.body.city, degreeType: 'F'}, (err, result) => {
if(err){
console.log(err);
}else{
res.render('pages/weather.ejs',{forecast: result});
}
});
});
app.listen(process.env.PORT, process.env.IP,() => {
console.log(`Server started on port ${process.env.IP}:${process.env.PORT}`);
});