This Error is Occurring based on the order of the route/function defined and i have also searched different reasons for this error's occurrence but din't come across this specific reason
//Save Task
router.get("/tasks/newrec",function(req,res,next){
var newtask={
title:"newtask5",
isdone:"true"
}
db.tasks.save(newtask,function(error,result){
if(error){res.send(error); }
else
{ res.send("success"); }//res.json(result);}
});
});
If i am declaring this function first then i see no error if i am declaring as second or third function then i see this error.I am using node with mongojs.
var express=require('express');
var router=express.Router();
var mongojs= require('mongojs');
var db=mongojs('taskdb',['tasks']);
//display all tasks
router.get('/tasks',function(req,res,next){
db.tasks.find(function(err,tasks){
res.json(tasks);
});
});
//To find single record with id
router.get('/tasks/:id',function(req,res,next){
var uid = req.params.id.toString();
db.tasks.findOne({_id:mongojs.ObjectId(uid)},function(err,doc){
res.json(doc);
});
});
//Save Task
router.get("/tasks/newrec",function(req,res,next){
var newtask={
title:"newtask5",
isdone:"true"
}
db.tasks.save(newtask,function(error,result){
if(error){res.send(error); }
else
{ res.send("success"); }//res.json(result);}
});
});