如何解决如何从Express Node JS中的另一个文件发送Promise响应
我有下面的代码,此代码没有问题,但是有一天会更大, 这样我想从另一个文件发送promise的响应 如果我们曾经使用laravel来自控制器,我们会将响应发送到资源
exports.products_post = (req,res,next) => {
const product = new Product({
_id: new mongoose.Types.ObjectId(),user_id: req.userData.userId,name: req.body.name,price: req.body.price,productImage: req.file.filename
});
product
.save()
.then(result => {
res.status(201).json({
message: "Created product successfully",createdProduct: {
name: result.name,user_id:result.user_id,price: result.price,productImage : result.productImage,_id: result._id,}
});
})
.catch(err => {
console.log(err);
res.status(500).json({
error: err
});
});
}
下面的零件代码我想保存到另一个文件
message: "Created product successfully",
我尝试过的方法是波纹管,但是没有用
exports.product_post = result => {
message: "Created product successfully",createdProduct: {
name: result.name,}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。