1
我正在制作一个nodejs api,其中我从db中获取申请人的所有记录。我的API网址是这样Nodejs api 404在访问url paremter时未发现错误
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
enter code here
var ApplicantCtrl = require('./controllers/applicantController');
var app = express();
var port = process.env.Port || 8000;
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.get('api/applicant/:applicantId/getFullDetails',
ApplicantCtrl.getApplicantAllData);
app.listen(port, function() {
console.log('Server is running on port : ' + port);
});
和applicantController.js代码是在这里
var connection = require('./../config');
var helpers = require('../helpers/helper');
module.exports.getApplicantAllData = function(req , res) {
var id = req.params.applicantId;
console.log('in applicantallData');
helpers.getApplicantFullData(id)
.then((data)=>{
if(data == null){
res.send({
meta : {status : 400, message : 'There is some error with query'}
});
}
else{
res.send({
meta : {status : 200, message : 'Success'},
data : data
});
}
})
.catch(function(err){
res.send({
meta : {status : 500, message : 'Internal Server Error'}
});
});
}
但是API响应是这样
Cannot GET /api/applicant/23/getFullDetails 404
任何一个可以告诉我,什么是错的吗?为什么api响应是404找到的。?
我没有提到我的server.js文件的完整代码。我正在更新我的代码。请参阅更新后的文章并相应地指导我。 –
其中是您正在安装的代码的一部分'ApplicantCtrl'?那部分仍然缺失?你应该拥有像Mikelax提到的东西。 app.use('/ api/applicant /:id/getFullDetails',ApplicantCtrl); –
@ J.D。我在我的文章中提到了我的AppicantCtrl代码。并在我的帖子的第一部分也是ApplicantCtrl安装代码,就像这样 var ApplicantCtrl = require('./ controllers/applicantController'); –