我想通过nodemailer将pdf报告附加到邮件给用户。我在前端使用jquery。
<script>
$(document).ready(function () {
var from, to, subject, text;
$("#send_email").click(function () {
to = $("#to").val();
subject = $("#subject").val();
text = $("#content").val();
$("#message").text("Sending E-mail...");
$.get("http://localhost:8080/send", {to: to, subject: subject, text: text}, function (data) {
if (data == "sent") {
$("#message").empty().html("Email is sent " + to + " .");
}
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
API 看起来像这样。而且效果很好。我想知道如何动态添加附件
app.get('/send', function (req, res) {
var mailOptions = {
to: req.query.to,
subject: req.query.subject,
text: req.query.text
};
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) { …Run Code Online (Sandbox Code Playgroud) 有没有办法node.js记录所有异常?
process.on('uncaughtException')对我来说是不够的,因为我需要记录所有捕获和未捕获的异常,即使catch代码中有某个地方忽略/吞噬了错误.
你觉得,有可能node.js吗?
我想扩展moment.js,以覆盖它的toJSON功能.
const moment = require('moment');
class m2 extends moment {
constructor(data) {
super(data);
this.toJSON = function () {
return 'STR';
};
}
}
const json = {
date: moment(),
};
const json2 = {
date: new m2(),
};
console.log(JSON.stringify(json)); // {"date":"2017-07-25T13:36:47.023Z"}
console.log(JSON.stringify(json2)); // {"date":"STR"}
Run Code Online (Sandbox Code Playgroud)
我的问题是,在这种情况下,我不能叫m2()无new:
const json3 = {
date: m2(), // TypeError: Class constructor m2 cannot be invoked without 'new'
};
Run Code Online (Sandbox Code Playgroud)
如何moment保持在没有new关键字的情况下调用它的能力?
覆盖moment.prototype.toJSON不是一个选项,因为我想moment在代码中的其他地方使用默认对象.
我正在尝试向类中添加额外的方法,这些额外的方法应该使用这些super方法.
如果我在模型定义中添加它们,它就可以工作.
class A {
doSomething() {
console.log('logSomething');
}
}
class B extends A {
doSomething() {
super.doSomething();
console.log('logSomethingElse');
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试添加额外的方法B.prototype,我会得到SyntaxError: 'super' keyword unexpected here.
class A {
doSomething() {
console.log('logSomething');
}
}
class B extends A {
}
B.prototype.doSomething = function doSomething() {
super.doSomething();
console.log('logSomethingElse');
}
Run Code Online (Sandbox Code Playgroud)
很明显,为什么我会收到这个错误.这是一个函数而不是类方法.
让我们尝试将方法定义为类方法,并将其复制到原始B类:
class A {
doSomething() {
console.log('logSomething');
}
}
class B extends A {}
class X {
doSomething() {
super.doSomething();
console.log('2 logSomethingElse');
} …Run Code Online (Sandbox Code Playgroud) 我尝试了很多变体,比如/[\u0FFF-\uFFFF]/,但它从来没有像我预期的那样对我有用。
之所以这么问,是因为mysql我用的版本不支持这些字符,有表情之类的就截字符串。为新版本更新 mysql 目前不是解决方案。
javascript ×4
ecmascript-6 ×2
node.js ×2
class ×1
jquery ×1
mean-stack ×1
momentjs ×1
nodemailer ×1
pdf ×1
regex ×1