My resume website is almost done, I'm just finalizing a "Contact me" form that should send me an e-mail with some plain text.
Here's what it looks like in Jade:
div.contact-email-box
form(id='contact-form' action='/' method='post')
h3 Contact me
div
label
span Name:
input(placeholder='e.g: Mark' type='text' tabindex='1' required autofocus)
div
label
span Email:
input(placeholder='e.g: mark@example.com' type='email' tabindex='2' required)
div
label
span Message:
textarea(tabindex='3' required)
div
button(name='Submit' type='submit' id='contact-submit') Send Email
And here's where I catch the POST
in my server.js
:
var express = require('express')
, app = express()
var nodemailer = require('nodemailer')
app.post('/', function(req, res) {
})
As you can see it does not do anything, yet I receive the following error:
/home/kade_c/website/node_modules/nodemailer/lib/mailer/index.js:31 compile: [(...args) => this._convertDataImages(...args)], ^^^
SyntaxError: Unexpected token ...
That happens only when I require('nodemailer')
even though it is installed correctly to my node_modules
.
Is this a known bug? How may I fix it?
Looks like a node version issue to me. The spread operator is not valid on earlier versions of Node,, check to make sure you are running a version that supports ES6 features.
Nodemailer is compatible with Node version 6 or above (as per https://nodemailer.com/about/#requirements)
So follow these steps to upgrade node:
1* sudo npm cache clean -f
2* sudo npm install -g n
3* sudo n stable
4* sudo ln -sf /usr/local/n/versions/node/5.4.1/bin/node /usr/bin/node (the bold text/version should be the one installed in during above step.)
ie if 8.1.1 is installed then do sudo ln -sf /usr/local/n/versions/node/8.1.1/bin/node /usr/bin/node
node –v (Should show updated version now)
Node.js version 6+ is must. Check your Node version with the following command:
node --version
If you are not at least 6+ then you must upgrade.
You may receive another error message instructing you to login to your account. In that case, go to your email inbox and you will see a message from Google with a link to a page for setting up less secure app permissions.