Created
November 12, 2019 09:32
-
-
Save josecarneiro/4859694df9bad0432a839de6113fed61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const http = require('http'); | |
const Pokedex = require('pokedex'); | |
const pokedex = new Pokedex(); | |
const server = http.createServer((request, response) => { | |
const endpoint = request.url; | |
const pokemonName = endpoint.substring(1); | |
try { | |
const pokemon = pokedex.pokemon(pokemonName); | |
// console.log(pokemon); | |
const pokemonInformation = `The pokemon ${pokemon.name} is number ${pokemon.id} in the pokedex and weighs ${pokemon.weight} lbs`; | |
const pokemonImage = pokemon.sprites.animated; | |
const htmlResponse = `<h3>${pokemonInformation}</h3><img src="${pokemonImage}" />`; | |
response.setHeader('Content-Type', 'text/html'); | |
response.write(htmlResponse); | |
} catch (error) { | |
response.write("That pokemon couldn't be found"); | |
} | |
response.end(); | |
}); | |
server.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment