-
Notifications
You must be signed in to change notification settings - Fork 649
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
0 parents
commit 0fab40b
Showing
6 changed files
with
430 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,2 @@ | ||
.DS_Store | ||
node_modules |
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 @@ | ||
web: node app.js |
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,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! |
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,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 | ||
}) |
Oops, something went wrong.