实际上,我有一个 NodeJS Express 应用程序,其配置文件包含主机、端口、JWT 令牌、数据库参数等参数。
问题是,将这些参数直接保留在环境变量上(没有任何配置文件)并访问它们,而不需要在所有组件和模块中进行“require”配置是否有意义。
我看到的所有示例都使用配置文件,可能与安全或内存有关?
我正在尝试使用 nodejs 和 nodemailer 发送邮件,但它对我不起作用。我有这个代码:
const config = require('../../config');
const http = require('http');
const nodemailer = require('nodemailer');
module.exports = {
sendMail: function (params) {
return new Promise((resolve, reject) => {
var transporter = nodemailer.createTransport({
//service: 'gmail', //I tried with this too
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: params.fromMail,
pass: params.fromPass
}
});
var mailOptions = {
from: params.fromMail,
to: params.toMailList,
subject: params.subject,
html: params.mailHtmlContent,
};
transporter.sendMail(mailOptions, function(err, info){
if (err) {
reject(err);
} else {
resolve(info.response);
} …Run Code Online (Sandbox Code Playgroud) 我想从 NodeJs 向特定用户发送通知。我们的想法是,如果可能的话,独立于 Firebase 和任何类型的第三方服务器。我找到了很多有关如何构建服务工作者的信息以及很多有关显示通知的信息,但我找不到任何可以对我有用的关于将推送消息发送到要显示的工作者的信息。
这是service-worker.js
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/layout/service-worker.js')
.then(function (registration) {
registration.pushManager.subscribe({
userVisibleOnly: true
}).then(function (subscription) {
isPushEnabled = true;
console.log("subscription.endpoint: ", subscription.endpoint);
//Here I will have to store the endpoint on my DB
});
}).catch(function (err) {
console.log(err);
});
}
//I think that this could be the listener, but I don't know how to trigger it from the server
this.onpush = function (event) {
console.log(event.data);
}
Run Code Online (Sandbox Code Playgroud)
我有这个代码用于显示通知(当我可以发送通知时)
var notificationTitle = 'Title';
var notificationOptions = { …Run Code Online (Sandbox Code Playgroud)