Nik*_*tov 2 javascript node.js nodemailer
我有一个问题,我正在尝试使用 nodemailer 执行发送邮件的文件,我需要从另一个 JS 文件中执行它,我尝试这样做:
const exec = require('child_process').exec;
exec('"C:/Users/NikitaSeliverstov/node_modules/.bin/send.js"');
Run Code Online (Sandbox Code Playgroud)
但邮件没有发送。我不需要发送 params 文件 send.js 只发送具有完全指定路径的文本文件。很抱歉有明显的问题,但我无法弄清楚。我也试着这样做:
const exec = require('child_process').exec;
exec('"node C:/Users/NikitaSeliverstov/node_modules/.bin/send.js"');
Run Code Online (Sandbox Code Playgroud)
您需要指定一个回调函数,该函数将在您的 exec 命令执行后调用:
我创建了 2 个文件:
另一个测试.js
console.log('another test');
Run Code Online (Sandbox Code Playgroud)
测试.js
const exec = require('child_process').exec;
const child = exec('node anotherTest.js',
(error, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
Run Code Online (Sandbox Code Playgroud)
这是输出:
stdout: another test
stderr:
Run Code Online (Sandbox Code Playgroud)
您可以通过在终端/控制台中执行“ node test.js ”来运行 test.js 脚本。您可以使用所需的参数更改 exec 命令的参数。
| 归档时间: |
|
| 查看次数: |
3529 次 |
| 最近记录: |