api请求无法正常工作

时间:2018-07-04 10:26:00

标签: javascript node.js post postman

我的api中具有此功能:

app.post('/api/create-project'),(req, res) => {
  console.log("hejhej");
  var newProject = new projectModel();
  newProject.questions = doc.sort((prev, current) => (prev.version > current.version) ? prev : current)[0];
  newProject.owner = req.body.owner;
  newProject.projectName = req.body.projectName;
  newProject.date = Date.now();
  newProject.version = 1.0;
  console.log(newProject)
  res.send(newProject)
  .catch(error => console.log(error))
}

但是当我尝试与邮递员联系并得到结果时,我得到了这个信息:

Cannot POST /api/create-project 

我发送的身体看起来像这样:

{
    "owner": "test",
    "projectname": "testing"
}

向:http://localhost:3000/api/create-project

似乎无法弄清楚,这可能有点愚蠢,但是..

1 个答案:

答案 0 :(得分:-2)

app.post('/ api / create-project',(req,res)=> {console.log(“ hejhej”); var newProject = new projectModel(); newProject.questions = doc.sort((( prev,current)=>(prev.version> current.version)?prev:current)[0]; newProject.owner = req.body.owner; newProject.projectName = req.body.projectName; newProject.date =日期。 now(); newProject.version = 1.0; console.log(newProject)res.send(newProject).catch(error => console.log(error))});

尝试一下