【发布时间】:2018-11-12 11:33:46
【问题描述】:
我在 nodejs 中从邮递员发送了一个请求,作为 nodejs 的初学者,我发现很难调试。有人可以对此有所了解吗? 这是此时的整个存储库。 https://github.com/kolaveridi/socialnetwork
router.get('/handle/:handle', (req, res) => {
console.log('working');
console.log(req.params.handle);
const errors = {};
Profile.findOne({ handle: req.params.handle })
.populate('user', ['name', 'avatar'])
.then(profile => {
if (!profile) {
errors.noprofile = 'There is no profile for this user';
console.log('no profile');
res.status(404).json(errors);
}
res.json(profile);
})
.catch(err => res.status(404).json(err));
});
我没有看到任何控制台正在发送此请求 当我已经有一个用户的句柄“妈妈”注册,登录。 http://localhost:5000/api/profile/handle/:mom
【问题讨论】:
-
起初,您的问题标题看起来非常笼统和糟糕。请更改它。遇到问题,我可以知道你得到的错误响应吗?我已经克隆了你的 repo 并在我的本地执行。我可以访问你的 api 并查看控制台日志。
-
@Sreehari 你能解释一下导致错误的原因吗?为什么我不能通过他的句柄访问用户。
-
为此,您需要向我提供错误。为您返回的错误是什么?你是如何测试它的?