I have javascript code that works fine on its own, but when i try to run it as an action from an HTML button, it says "Uncaught ReferenceError: require is not defined. Javascript is supposed to send an email, which i have succesfully done running it through command promopt. code is below, I did remove PI as it used my email adress and password.
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<button onclick=myFunction()>What is the time?</button>
<script>
function myFunction() {
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'hotmail',
auth: {
user: [REMOVED]
pass: [REMOVED]
}
});
var mailOptions = {
from: [REMOVED]
to: [REMOVED]
subject: [REMOVED]
text: [REMOVED]
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
</script>
</body>
</html>
"
tried inlcuding the file with javascript seperately, same error.