I'm new in programming and currently learning node.js and express.js
I have a form for user to contact me when submitted it should open windows mail app, in javascript I can just use document.createElement('a')
but when I use it on node.js it says 'document' is not defined or createElement is not a function
I've tried to use jsdom
Here's the js code:
app.post('/contact-me', function(req, res) {
let name = req.body.userName
let email = req.body.userEmail
let phone = req.body.userPhoneNumber
let subject = req.body.userSubject
let message = req.body.userMessage
let form = req.body.contact /
let contact = {
name,
email,
phone,
subject,
message
}
let openMail = new JSDOM(contact) //I've also tried let openMail = new JSDOM(form)
let myEmail = "dev@mail.com"
let a = openMail.window.document.createElement('a')
a.href = `mailto:${myEmail}?subject=${subject}&body=Hello, my name is ${name}, ${subject}, ${message}`
a.click()
})`
Form opening tag: <form class="form-container" action="/contact" method="POST" name="contact">
But it says:
Error: Not implemented: navigation (except hash changes)
at module.exports (D:\folder\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
at navigateFetch (D:\folder\node_modules\jsdom\lib\jsdom\living\window\navigation.js:77:3)
at exports.navigate (D:\folder\node_modules\jsdom\lib\jsdom\living\window\navigation.js:55:3)
at Timeout._onTimeout (D:\folder\node_modules\jsdom\lib\jsdom\living\nodes\HTMLHyperlinkElementUtils-impl.js:81:7)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) undefined
Do node.js have different code or I have to do something before using DOM?