简体   繁体   English

控制台无法编译Node.js

[英]Console doesn't compile nodejs

I have a denwer local server and node.js 10.16.2. 我有一个本地服务器和node.js 10.16.2。 I have a main folder(with all files) and subfolder 'question'. 我有一个主文件夹(包含所有文件)和子文件夹“ question”。 There is file quest.js in 'question'. “ question”中有文件quest.js。 I send the POST request to the port 8001 from index.html file. 我将index.html文件中的POST请求发送到端口8001。

const express = require("express");

const app = express();

var bodyParser = require('body-parser');

var urlencodedParser = bodyParser.urlencoded({extended: false});

var nodemailer = require('nodemailer');

var data = {}; 

app.listen(8001);

app.post('/', urlencodedParser, function(req, res) {
    data = req.body;
    res.redirect('Z:/denwer/www/denwer/asksuccess/suc.html?name='+data.name);
    var transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
          user: 'mygmail@gmail.com',
          pass: 'mypassword'
        }
      });

      var mailOptions = {
        from: 'myemail@gmail.com',
        to: 'emails@gmail.com',
        subject: 'Вопрос по корсетам',
        html: 'Имя:'+data.name+'<br>Email:'+data.email+'<br>Телефон:'+data.telephon+'<br>Вопрос:<br><br>'+data.question
      };

      transporter.sendMail(mailOptions);
});

I wrote in the console: node quest.js but it hasn't given me any result. 我在控制台中写道:节点quest.js,但没有给我任何结果。 I waited for an empty output and new line but it hasn't compiled. 我等待一个空的输出和换行符,但尚未编译。

Just write console.log('Working...') somewhere in the file to see if the file is being read. 只需将console.log('Working ...')写入文件中的某处以查看是否正在读取文件。 Also, you can pass a function to app.listen and add a console.log in there to see if the app is listening for requests. 另外,您可以将函数传递给app.listen并在其中添加console.log,以查看应用程序是否正在侦听请求。 Something like 就像是

app.listen(8001, function () {
  console.log('Listening on port 8001');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM