PokeAPI / pokedex-promise-v2

An easy way to use pokeapi v2 with promises in node.js
MIT License
510 stars 89 forks source link

"res" is not defined #7

Closed abhi18av closed 8 years ago

abhi18av commented 8 years ago

Hey, I'm trying to use the wonderful wrapper in NodeJS but for some reason I'm unable to get this thing running. I'm a passionate noob starting out with the Web so could you please help me out a bit.

Here are the specs

'''bash There was an ERROR: [ReferenceError: res is not defined] '''


npm - 2.15.5
nodejs - v4.4.5

Directory setup

├── node_modules │   ├── pokedex-promise-v2 │   └── promise ├── package.json └── pokefile1.js

Naramsim commented 8 years ago

Hi, thanks for using this wrapper. You are getting that error because res is not defined. Usually, this wrapper is used along express.js which lets you do the following:

var express = require('express');
var app = express();

app.get('/', function (req, res) { // res here is a parameter
  res.send('Hello World!'); //you use it for serving content to clients
});

So in the examples we use res to show how to serve the content retrieved from the PokeAPI while using express.

To test if your installation works fine just use this code:

var Pokedex = require('pokedex-promise-v2');
var P = new Pokedex();
P.getBerryByName('chesto')
    .then(function(response) {
      console.log(response);
    })

It will log you the response Object. No need to use res and express

abhi18av commented 8 years ago

Ah, yes now it works perfectly! I appreciate the explanation. Grazie Allesandro! 👍