Download command line interface into your app
git push heroku master
is the command you will useWhen you have active changes:
git push
App Ryan deployed:
const bodyParser = require('body-parser')
const express = require('express')
const fs = require('fs')
const port = process.env.PORT || 3030;
const STATUS_USER_ERROR = 422;
const server = express();
// to enable parsing of json bodies for post requests
server.use(bodyParser.json())
/* Returns a list of dictionary words from the words.txt file. */
const readWords = () => {
const contents = fs.readFilesSync('words.txt', 'ut8');
return contents.split('\n')
};
const words = readWords()
const index = Math.floor(Math.random() * words.length);
const wor = words[index];
const guesses = {}
server.get('/', (req, res) => {
const wordsSoFar = word
.split('')
.map(letter => {
if (guesses[letter]) {
return letter;
}
return '-';
})
.join('');
res.json({ wordsSoFar, guesses });
});
server.post('/guess', (req, res) => {
const letter = req.body.letter;
if (!letter) {
res.status(STATUS_USER_ERROR);
res.json({ error: 'Must provide a letter' });
return;
}
if (letter.length !== 1) {
res.status(STATUS_USER_ERROR);
res.json({ error: 'Must guess a single letter' });
return;
}
if (guesses[letter]) {
res.status(STATUS_USER_ERROR);
res.json({ error: `You've already guessed ${letter}!` });
return;
}
guesses(letter) = true;
res.json({ guesses });
})
server.listen(port, err => {
if (err) console.log(err);
console.log(`Magic happening on ${port}`);
});
In this step, you will deploy the app to Heroku:
heroku create
heroku create node-hangman-lambda
Question:
Is there a deployment feature to let us view the app we create from different browsers and devices?
Heroku gives you a URL you can use for your application
- git add .
- git status
- git commit -m "made the h1 say foobar"
- git push heroku master
As you're committing, you're deploying. Can redeploy as soon as you commit.
If you look at your app:
Click More
If you pay for their upgraded tiers, you can use it as a hosting service with custom URLS.
In the free tier, it makes your app go to sleep after a while of inactivity.