This was an assigment using the following instructions. It took about 5 hours to complete using class notes and some previous githubs. I copied and pasted this ReadMe from https://github.com/IamCharlesM/wdi-10-hw11-express-index-show-poke/blob/master/README.md thanks a lot, hope this helps whoever is learning EJS
Original creators: WDI-Lettuce, WDIR-Panthalassa, Thom Page
Adapted by: Kristyn Bryan
Further Adaptations by: Karolin Rafalski and Reuben Ayres
Competencies: Practicing Index and Show pages
Prerequisites: Javascript, Express, Routes, Node
Make a Pokemon app that displays data inside server-side rendered views.
User Stories
index
of pokemon: the names of each pokemon rendered to the page.show
page, and will see the pokemon’s name and image.In terminal:
mkdir pokemon_app
cd pokemon_app
mkdir views
touch views/index.ejs
touch views/show.ejs
mkdir models
touch models/pokemon.js
touch server.js
npm init
npm init
promptssubl .
(Sierra: open the whole folder structure from the file->open menu)</details>
🔴 The commit message should read:
“Commit 1 - All my files are created”
In terminal:
package.json
(why?)npm install express ejs
package.json
</details>
🔴 The commit message should read:
“Commit 2 - All my npm packages are added”
server.js
set up your serverexpress()
to a variableport
to 3000
/
that will res.send('Welcome to the Pokemon App!');
So that when you got to localhost:3000
, you will see Welcome to the Pokemon App!
nodemon
or nodemon server.js
(if you set your up your package.json
to start server.js
you do’t need to put it after nodemon
)
-GOTCHA! : nodemon will only work if you run it from the same location as your package.json
localhost:3000
Welcome to the Pokemon App!
message displaying🔴 The commit message should read:
“Commit 3 - My server is set up and running”
pokemon.js
const pokemon = [ {name: "Bulbasaur", img: "http://img.pokemondb.net/artwork/bulbasaur.jpg"},
{name: "Ivysaur", img: "http://img.pokemondb.net/artwork/ivysaur.jpg"},
{name: "Venusaur", img: "http://img.pokemondb.net/artwork/venusaur.jpg"},
{name: "Charmander", img: "http://img.pokemondb.net/artwork/charmander.jpg"},
{name: "Charizard", img: "http://img.pokemondb.net/artwork/charizard.jpg"},
{name: "Squirtle", img: "http://img.pokemondb.net/artwork/squirtle.jpg"},
{name: "Wartortle", img: "http://img.pokemondb.net/artwork/wartortle.jpg"}
];
server.js
and then be required by your server.js
pokemon
in your server.js
file/pokemon
that will res.send(pokemon)
, which will display your pokemon data as json in the browser🔴 The commit message should read:
“Commit 4 - Connected my database, can see json in the browser”
/pokemon
route, you should serve the index.ejs
file you created that will display your pokemon<h1>
that describes this page, i.e. ‘See All The Pokemon!’<style>
tag so you can write some CSS directly in your html file. More info - In the Hungry for More section - you can work on properly linking a CSS file.<style>
tag to be sure it is working as expected. Example:
<style type="text/css">
body {
color: blanchedalmond;
background-color: steelblue;
}
</style>
<style>
tag/pokemon
route to res.render
your index.ejs
filelocalhost:3000/pokemon
and be sure to see your index.ejs
view with h1 tag🔴 The commit message should read:
“Commit 5 - index.ejs view rendered at pokemon route”
index.ejs
view so that you can see:
🔴 The commit message should read: <br>
"Commit 6 - I can view a list of all my pokemon in the browser "
server.js
, add a new get route /pokemon/:id
res.send(req.params.id);
localhost:3000/pokemon/whatever
whatever
will show up in the browser🔴 The commit message should read:
“Commit 7 - show view shows req.params.id “
index.ejs
to your show.ejs
index.ejs
,<a>
tag that will have an href
that goes to the route /pokemon/x
, where x is the array position of the pokemon
in the data array. This should be set dynamically with ejs🔴 The commit message should read:
“Commit 8 - added dynamic anchor tags to index.ejs “
index.ejs
into your show.ejs
(surely, there must be a better way; are you wondering if there is something in the hungry for more section about this?)show.ejs
file’s <body>
so that
back
, that will take you back to your index.ejs
view🔴 The commit message should read:
“Commit 9 - created show views of each pokemon “
🔴 The commit message should read:
“Commit 10 - set up serving of static files so we can add CSS”
Set up gulp to compile LESS (like in class) and have it spit out the CSS file to your static files area you just set up.
Pro tip: you might like to open third terminal tab where you keep gulp running (one for nodemon, one for gulp, and one for regular terminal stuff like making files and doing git)
🔴 The commit message should read:
“Commit 11 - added gulp and configured it to compile LESS”
</details>
🔴 The commit message should read:
“Commit 12 - Styled app with LESS”
Style your application with Bootstrap! Or really jazz up your app by adding some hand-rolled flourishes with css animations, jQuery and more!
not()
~ 5 minutes