Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LinKCoding committed Nov 16, 2020
0 parents commit 0fab40b
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
node_modules
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node app.js
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Deploying a Back-end with Heroku
Hello! This GitHub repo is intended to be used with the article [Deploying a Back-end with Heroku
](https://www.codecademy.com/articles/deploying-a-back-end-with-heroku)

Make sure to follow the steps as outlined in the article to see how to use Heroku for your deployment needs!

You're free to make changes on your own branch, but for the sake of consistency, we will not be merging any external pull requests. Thank you and happy coding!
17 changes: 17 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const express = require('express'); // import express module (simplifies routing/requests, among other things)
const app = express(); // create an instance of the express module (app is the conventional variable name used)
const fetch = require('node-fetch'); // import node-fetch (enables the fetch API to be used server-side)
const PORT = process.env.PORT || 5000; // use either the host env var port (PORT) provided by Heroku or the local port (5000) on your machine

app.get('/', (req, res) => { // send a get request to root directory ('/' is this file (app.js))
fetch('https://www.boredapi.com/api/activity') // fetch activity from bored API - https://www.boredapi.com/about
.then(res => res.json()) // return a promise containing the response
.then(json => res.send(`<h1>Today's Activity: ${json.activity}!</h1>`)) // extract the JSON body content from the response (specifically the activity value) and sends it to the client
.catch(function(err){ // catch any errors
console.log(err); // log errors to the console
})
})

app.listen(PORT, () => { // start server and listen on specified port
console.log(`App is running on ${PORT}`) // confirm server is running and log port to the console
})
Loading

0 comments on commit 0fab40b

Please sign in to comment.