-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
606d4c7
commit 49b9055
Showing
22 changed files
with
2,446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const express = require("express"); | ||
const app = express(); | ||
const $fetch = require('node-fetch'); | ||
const chalk = require('chalk'); | ||
|
||
const logger = require('morgan'); | ||
app.use(logger('dev')); | ||
|
||
app.set("view engine", "ejs"); | ||
app.use(express.static('public')); | ||
|
||
const baseUrl = 'https://api.coindesk.com/v1' | ||
// https://api.coindesk.com/v1/bpi/currentprice.json | ||
|
||
app.get('/', (req, res)=> { | ||
res.render('index'); | ||
}) | ||
|
||
app.get('/results', (req, res)=> { | ||
let route = 'bpi/currentprice.json'; | ||
let endpoint = `${baseUrl}/${route}`; | ||
|
||
$fetch(endpoint) | ||
.then(response => { | ||
if(response.status === 200) { | ||
return response.json() | ||
} else { | ||
throw Error('JM did it!') | ||
} | ||
}) | ||
.then(data => { | ||
console.log(data) | ||
res.render('results', {data: data, currencyQuery: req.query.currency}) | ||
}) | ||
.catch((err) => res.send(err.message)); | ||
|
||
}); | ||
|
||
app.get('*', (req, res)=> { | ||
res.send("I don't exist.") | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
app.listen(PORT, ()=>{console.log(chalk.green(`Running on port ${chalk.blue(PORT)}`))}); |
Oops, something went wrong.