Express GET Route无效

时间:2016-01-23 20:53:51

标签: javascript node.js express mongoose url-routing

我使用Node和Express开发了一个REST API。我正在尝试获取列表项。每个todo列表项都包含id和text属性。我想要做的是有GET路由,这将允许我通过传递id作为路由参数来获取特定的todo列表项。我已经尝试了几次尝试,但无法看到我做错了什么。我的代码是:

我的数据库

var mongoose = require('mongoose');

module.exports = mongoose.model('Todo', {
  text : String,
  done : Boolean
});

// get all todos list items
app.get('/api/todoo', function(req, res) {

  // use mongoose to get all todos in the database
  Todo.find(function(err, todos) {

  // if there is an error retrieving, send the error. nothing after res.send(err) will execute
    if (err)
      res.send(err)

    res.json(todos); // return all todos in JSON format
  });
});


//Getting a todo list by ID

app.get('/api/todoo/:todo_id', function(req, res) {
  Todo.find({id : req.params.todo_id}, 
    function(err, todo) {
      if (err)
        res.send(err);

      res.json(todos);
  });
}); 

1 个答案:

答案 0 :(得分:0)

只是打算'todoo'打算'todo'吗?