javascript - Trying to create a function nodejs express -
im trying create function dont use same code again , again keep getting internal error.i data , internal error if change need refresh page updated.i cant understand why error.here error
get http://localhost:3000/api/pages 500 (internal server error)
object {data: "", status: 500, config: object, statustext: "internal server error"}
code:
function get(some,that,res){ return some.find(function(err,that) { if (!err) { return res.send(that); } else { return res.send(500, err); } }); }; router.get('/pages', sessioncheck, function() { get(page,pages,res); });
update: might doing wrong lets take start.how can create function dont reuse same code again , again.
router.get('/pages', function(request, response) { return page.find(function(err, pages) { if (!err) { return response.send(pages); } else { return response.send(500, err); } }); });
and here full code
var express = require('express'); var router = express.router(); var mongoose = require('mongoose'); var page= require('../models/page.js'); var bcrypt = require('bcrypt-nodejs'); function get(some,that,response){ return some.find(function(that,err) { if (!err) { return response.send(that); } else { return response.send(500, err); } }); }; router.get('/pages', sessioncheck, function(request,response) { get(page,pages,response); });
router.method first call function sessioncheck. need call next() within sessioncheck call next function, in not defining parameters (typically define req, res).
Comments
Post a Comment