json - Express REST API response methods are not recognized -


i have simple request returns json trying implement. have followed tutorials express web framework rest api, reason keep getting same error

error:

typeerror: res.status not function 

or

typeerror: res.json not function 

index.js:

 var express = require('express');     var router = express.router();     var pg = require('pg');     var connectionstring = 'pg://postgres:postgres@postgres/feed';  /* home page. */ router.get('/', function(req, res, next) {   res.render('index', { title: 'express' });  });  router.get('/api/leaderboard', function(resp, req){   var results = [];    pg.connect(connectionstring, function(err, client, done){        if(err){          done();          console.log(err);          return res.status(500).json({ success: false, data: err});        }        var query = client.query("select * log (logged >= date_trunc('week', current_timestamp - interval '1 week') , logged <= date_trunc('week', current_timestamp));");        var counter = 0;        var b1 = {};        var b2 = {};        var b3 = {};        var b4 = {};        b1.energy_sum_week = 0;        b2.energy_sum_week = 0;        b3.energy_sum_week = 0;        b4.energy_sum_week = 0;        b1.zne_sum_week = 30000;        b2.zne_sum_week = 30000;        b3.zne_sum_week = 30000;        b4.zne_sum_week = 30000;        query.on('row', function(row){            //results.push(row);                   if(row['address'] == 215){                      b1.energy_sum_week = row['kitchen'] + row['plugload'] + row['lights'] + row['ev'] + row['hvac'] + row['instahot'] - row['solar'];                    }                    else if (row['address'] == 1590) {                      b2.energy_sum_week = row['kitchen'] + row['plugload'] + row['lights'] + row['ev'] + row['hvac'] + row['instahot'] - row['solar'];                     } else if (row['address'] == 1605) {                      console.log(row);                      b3.energy_sum_week = row['kitchen'] + row['plugload'] + row['lights'] + row['ev'] + row['hvac'] + row['instahot'] - row['solar'];                     } else if (row['address'] == 1715) {                      b4.energy_sum_week = row['kitchen'] + row['plugload'] + row['lights'] + row['ev'] + row['hvac'] + row['instahot'] - row['solar'];                    }         });        query.on('end', function(){          done();          //make zne lower          results.push(b1);          results.push(b2);          results.push(b3);          results.push(b4);          resp.json(results);         });    });  });   module.exports = router; 

it seems can't recognize response object. tried bunch of different things passing in request , response's query callbacks, , using promises. getting kinda desperate here :/

the res variable doesn't exist in current context, expect line

router.get('/api/leaderboard', function(resp, req){ 

had form

router.get('/api/leaderboard', function(req, res){ 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo