如何使用nodemailer为NodeJS应用程序在后台发送电子邮件?

我正在构build一个Angular 4和Node应用程序。 一旦任何用户在前端注册,我将其数据存储在数据库中,然后想要使用nodemailer包向他们发送成功的注册电子邮件。 这是Node js代码: router.post('/', function(req, res, next) { SOME_DATABASE_FUNC() { if(FAILED_CASE) { return res.status(500).json({ title: 'An error occurred', status: 500, error: error }); var mailOptions {…} transporter.sendMail(mailOptions, function (error, info) { if (error) { console.log(error); return res.status(500).json({ title: 'An error occurred', status: 500, error: error }); } console.log('Message', info.messageId, info.response); return res.status(200).json({ message: […]

错误:加载块0失败。 – webpack试图加载0.js

我有以下项目结构: |-mainFile.js |-scripts – |-Library1.js |-Library2.js 库文件使用requirejs define([], function() {})语法。 所以我把它放到了webpack.config.js中: module.exports = { resolve: { modules: [ path.resolve(__dirname, 'scripts'), // The normal path "node_modules" ] }, /** … **/ } 然后我在webpack的入口点mainFile.js中做这个: require(["Library1", "Library2"], function(Library1, Library2) { … }); 我得到这个错误: GET http://localhost:3000/0.js [HTTP/1.1 404 Not Found 3ms] Error: Loading chunk 0 failed. Stack trace: onScriptComplete@http://localhost:3000/player/webpack_build.js:100:24 […]

如何构build和部署meteor应用从开发机器到离线生产机器?

我正在尝试meteor。 我开发了一个使用mongodb的基本webapp。 现在,这个应用程序需要部署在目标机器上(win32),具有以下要求。 目标机器只是一台PC,使用它的人不是一个开发人员。 所以,如果我可以将它们指向单个安装程序(对于运行时…我想一些nodejs + mongodb捆绑包?)会很好。 build立和部署应用程序到他们的个人电脑的文件夹。 “meteorbuild立”产生一个很好的压缩,但它似乎并不像一个生产版本,即包含大量的可读的JavaScript文件夹。 难道仅仅为server-app构build一个简化的js,为client-app构build一个缩小的js + html + css组合是不可能的? 目标机器将大部分不在互联网上,偶尔会上网(每天一次)。 我想这应该是好的,因为应用程序的用户将只是局域网内的其他机器。

刮cheerio.js,得到:错误:只能在暂停时执行操作

试图从这个网站刮取威士忌的名字,image_url和描述: https ://www.thewhiskyexchange.com/c/33/american-whiskey ? filter = true#productlist-filter using cheerio.js。 我想把这些信息转换成一个JSON对象数组来存储在我的MongoDB中。 无法显示整个网站的html,但这里是无序列表的相关基本结构的一部分: <body> <div class="siteWrapper"> <div class="wrapper"> <div class="products-wrapper"> <ul class="products-list"> <li> <a> <div class="product-content"> <div class="information"> <p class="name"> " Jack Daniel's Old No. 7" <span>Small Bottle</span> </p> </div> </div> </a> </li> <li></li> <li></li> etc. </all closing tags> 刚开始试图在<p class="name">得到威士忌的名字,没有任何来自<span>标签的文本,我在浏览器控制台中使用了这个jQuery代码,它正是我所需要的: $('ul.products-list > li').each(function(index) { const nameOnly […]

尝试通过Firebase云端function发送通知(Android)后出现错误

我是Firebase和nodejs的新手。 我正尝试使用Firebase云端函数从一台设备向另一台设备发送通知。 这是发送通知的node.js代码: var functions = require('firebase-functions'); var admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/sendNotification/{notificationId}') .onWrite(event => { var regToken="fYRweeL8cic:APA91bH6Q_gyKKrLL…"; // Grab the current value of what was written to the Realtime Database. var eventSnapshot = event.data; var payload = { data: { title: eventSnapshot.child("title").val() } }; // Set the message as high priority and […]

SequelizeBaseError:列“…”不存在

遇到使用sequelize表的错误join“belongsTo”和“hasMany; SequelizeBaseError:列videos.eventEventId不存在。 我没有在模型或数据库中的这列,并没有引用路由器中的任何地方 – 不知道为什么这个错误是返回时,我没有这个在我的模型或表? 似乎出现在对事件模型的主键的任何引用上。 const Sequelize = require('sequelize') // Heroku postgres db connection const sequelize = new Sequelize(process.env.DATABASE_URL, { dialect: 'postgres', protocol: 'postgres', define: { timestamps: false, }, dialectOptions: { ssl: true } }); // Connect all the models/tables in the database to a db object, //so everything is accessible via one object […]

显示错误的angular度cli安装命令

npm install -g @angular/cli 我想在Windows 10上安装angular度cli,我已经安装了npm和node,并且已经validation了他们的版本,他们是在angular度cli安装时所需要的,但是当我在提示符下运行安装命令时显示错误。

在Node.js和Express中loggingangular色

我是Node.js和Express中的新成员,并且使用Passport访问控制存在问题。 我想检查用户login的angular色。 我的用户架构: let mongoose = require('mongoose'); let userSchema = new mongoose.Schema({ name:{ type: String, required: true }, email:{ type: String, required: true }, password:{ type: String, required: true }, username:{ type: String, required: true }, role:{ type: String, default: 'user' }, activated:{ type: Boolean, default: false } }); let User = module.exports = mongoose.model('User', […]

我怎样才能将参数从Express路由传递到Node中间件

我无法在文档中find答案,我希望有办法做我所需要的。 我有一些快递路线: app.post( '/submit-agency-event' , eventService.submitEvent ); app.post( '/submit-question' , formService.submitQuestion ); app.post( '/submit-information-request' , formService.submitInformationRequest ); app.post( '/social-worker-register-family' , familyService.registerFamily ); 每个路由使用中间件文件中的函数来处理请求。 我想限制一个路由只有一些用户types(这是存储在req.user.userType )。 我想设置类似于以下的路线: app.post( '/social-worker-register-child' , middleware.requireUsersOfType( ['admin, social worker'] ), childService.registerChild ); 那么在调用requireUsersOfType() ,使用函数requireUsersOfType()来处理处理和任何所需的redirect。 exports.requireUsersOfType = ( req, res, next, userTypesArray ) => { // processing }; 我似乎无法弄清楚的是如何将parameter passing给requireUsersOfType()函数。 有谁知道这可以做到吗?

多个asynchronous/等待try-catch块

我在这里,因为我有麻烦debugging我的应用程序。 这是非常烦人的,不明白为什么我的应用程序崩溃。 我使用承诺(随着/ catch块),但我得到使用asynchronous/等待的必要性。 我有一个方法,我做多个等待它。 这里的问题是,如果我的应用程序崩溃,因为任何原因,我永远不知道它是什么问题。 我已经描述过这样的块: static async processCSGOGroupsAndUsers (groupName) { try{ const csgoApiData = await csgoApi(groupName); const parsedData = await xmltojson(csgoApiData); const id = parsedData.memberList.groupID64; //const members = await retrieveMembers(groupName, parsedData.memberList.memberCount); const totalUsers = await UsersService.processCSGOUsers(id, parsedData); const csgoGroup = { name: parsedData.memberList.groupDetails.groupName, siteUrl: parsedData.memberList.groupDetails.groupURL, id, totalUsers }; await GroupsDao.save(csgoGroup); }catch (err){ return […]