错误:'路径未定义'而我试图启动服务器

时间:2018-06-16 13:38:09

标签: javascript express

大家好我正在尝试使用this教程为我的React Native应用创建忘记/重置密码服务。但是当我尝试启动服务器时,我收到有关路径的以下错误。

ReferenceError: path is not defined at Object.<anonymous> (/home/ubuntu/server/services/handlebars.js:16:15)

现在这是我的文件夹结构

-server
 -controllers
   authentication_controller.js
 -models
   user.js
 -services
   handlebars.js
   passport.js
   router.js
 -templates
   forgot-password-email-template.html
   reset-password-email-template.html
 index.js

这是我的handlebars.js

var hbs = require('nodemailer-express-handlebars'),
    email = process.env.MAILER_EMAIL_ID || 'email@gmail.com',
    password = process.env.MAILER_PASSWORD || 'email_password'
    nodemailer = require('nodemailer');

var smtpTransport = nodemailer.createTransport({
    service: process.env.MAILER_SERVICE_PROVIDER || 'Gmail',
    auth: {
        user: email,
        password: password
    }
});

var handlebarsOptions = {
    viewEngine: 'handlebars',
    viewPath: path.resolve('../templates'),
    extName: '.html'
};

smtpTransport.use('compile', hbs(handlebarsOptions));

1 个答案:

答案 0 :(得分:0)

此处发生错误:

var handlebarsOptions = {
    viewEngine: 'handlebars',
    viewPath: path.resolve('../templates'),
    extName: '.html'
};

require('path')文件开头的handlebars.js错综复杂:

var hbs = require('nodemailer-express-handlebars'),
    email = process.env.MAILER_EMAIL_ID || 'email@gmail.com',
    password = process.env.MAILER_PASSWORD || 'email_password'
    nodemailer = require('nodemailer'),
    path = require('path');