Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaiimusician authored Aug 28, 2021
1 parent 606d4c7 commit 49b9055
Show file tree
Hide file tree
Showing 22 changed files with 2,446 additions and 0 deletions.
44 changes: 44 additions & 0 deletions S9_P1-Bitcoin/index.js
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)}`))});
Loading

0 comments on commit 49b9055

Please sign in to comment.