-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
50 lines (39 loc) · 1.4 KB
/
index.mjs
File metadata and controls
50 lines (39 loc) · 1.4 KB
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
46
47
48
49
50
import express from 'express';
import fetch from 'node-fetch';
const solarSystem = (await import('npm-solarsystem')).default;
const app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
//root route
app.get('/', async (req, res) => {
let response = await fetch("https://pixabay.com/api/?key=20426927-497d14db9c234faf7d0df8317&per_page=50&orientation=horizontal&q=solar+system+planets+space");
let data = await response.json();
const randomIndex = Math.floor(Math.random() * data.hits.length);
const randomImgUrl = data.hits[randomIndex].largeImageURL;
console.log(data);
res.render('home.ejs', {randomImgUrl})
});
app.get('/planet', (req, res) => {
let planet_name = req.query.planetName;
let planetInfo = solarSystem[`get${planet_name}`]();
// console.log(planetInfo);
res.render('planetInfo.ejs', {planetInfo, planet_name});
});
app.get('/nasaPod', (req, res) => {
// console.log(planetInfo);
res.render('nasaPod.ejs');
});
// //mercury route
// app.get('/mercury', (req, res) => {
// let planetInfo = solarSystem.getMercury();
// console.log(planetInfo);
// res.render('mercury.ejs', {planetInfo});
// });
// app.get('/venus', (req, res) => {
// let planetInfo = solarSystem.getVenus();
// console.log(planetInfo);
// res.render('venus.ejs', {planetInfo});
// });
app.listen(3000, () => {
console.log('server started');
});