如何启用从cpanel登录的node.js应用程序? [英] How can I enable node.js application logs on from cpanel?

查看:74
本文介绍了如何启用从cpanel登录的node.js应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个node.js应用程序,该应用程序使用nodemailer发送电子邮件.从localhost可以正常工作,但是当我从服务器尝试时,我无法收到任何邮件.

I have a node.js application that sends email using nodemailer. It is working fine from localhost but when I try it from server I can't receive any mail.

因为,应用程序的其他活动均正常运行,这意味着我认为nodemailer已正确安装在服务器上.我尝试使用主机作为服务器和使用gmail作为服务中的两种方式.这是我上次尝试的方法.这在本地主机上也可以正常工作.但是,将其放在服务器上时没有任何反应.

Since, other activities of application are working fine means I assumed nodemailer is installed properly on server. I tried on both ways using host as my server and using gmail as on of the services. Here, is what I tried last time. This also works fine on local host. But, I don't get any response when I put this on server.

我的nodemailer配置为:

I have nodemailer's configuration as:


const output = `
    <h3>Limit Details</h3>
    <p>Admin has added ${limit} quota(s) to ${username}.</p>
  `;

  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    service: 'gmail',
    port: 25,
    secure: false, // true for 465, false for other ports
    auth: {
        user: '<gmail>', 
        pass: '<password>' 
    }
  });

  // setup email data with unicode symbols
  let mailOptions = {
      from: '"Sender" <sender gmail>', // sender address
      to: '<receiver gmail>', // list of receivers
      subject: 'Quota added information.', // Subject line
      html: output // html body
  };

  // send mail with defined transport object
  transporter.sendMail(mailOptions, (error, info) => {
      if (error) {
          return console.log(error);
      }
      console.log('Message sent: %s', info.messageId);   
      console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
  });

为了进行测试,我已经控制台了messageId和Preview Url那么,从哪里可以在cpanel中查看此控制台消息?如何在cpanel的应用程序中查看此类控制台内容?

For testing, I have consoled messageId and Preview Url So, from where I can view this console message in cpanel? How can I view such consoled stuffs from my application in cpanel??

推荐答案

cPanel的应用程序管理器不是很完善.我一直在尝试,并将其与我习惯的(PM2)进行比较,并将切换回PM2.如果有人有兴趣支持,我确实向cPanel提出了功能请求.

cPanel's Application manager isn't very fleshed-out. I've been trying it out and comparing it to what I'm used to (PM2) and will be switching back to PM2. I did put up a feature request to cPanel if anyone's interested in supporting.

否则,答案是使用@zenott建议的自定义记录器将其写出.但是,我更喜欢覆盖console.log,因此如果需要,可以很容易地切换回常规控制台日志.

Otherwise, the answer is to write out using a custom logger such as @zenott suggests. However, I prefer to overwrite console.log though so it's easy to switch back to regular console logging if needed.

我的解决方案:

const moment = require('moment')
const fs = require('fs')
let logStream = fs.createWriteStream('log.txt')
let console = {}
console.log = (obj) => {
  var s = ''
  if (typeof obj === 'string')
    s = obj
  else
    s = JSON.stringify(obj)

  var dS = '[' + moment().format(momentFormat) + '] '
  s = `[${dS}] ${s}'\n'`
  logStream.write(s)
}

这篇关于如何启用从cpanel登录的node.js应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆