我有一个模型 Transactions
,其中我创建了一个 beforeCreate
方法,如下所示:
beforeCreate(values,cb){
//I want this code to be run in just production enviroment, not in devlopement env
EmailService.sendMail(values.email,values.data);
cb();
}
这里我创建了一个服务EmailService
,它将向用户发送邮件。但我确实希望它仅在生产环境中有效,而不是在开发环境中有效。
我不想评论这一行,因为我有很多其他事件只能在生产环境中触发,而不是在测试环境中触发。如何做到这一点?
最佳答案
beforeCreate(values,cb){
//I want this code to be run in just production enviroment, not in devlopement env
if (sails.config.environment === 'production') {
EmailService.sendMail(values.email,values.data);
}
cb();
}
关于node.js - sails js(node js框架)中仅在生产环境中运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41649268/