0

jquery & node js ReferenceError: $ is not defined

hi guys, i have a problem when i launch file js with comand prompt with the following code. thank's for help // JavaScript var nome = ""; var cognome = ""; var email = ""; var phone = ""; var comments = ""; var prodotto =""; var totale = ""; var resoconto = $(function() { nome += $("#name").val(); cognome += $("#cognome").val(); email += $("#email").val(); phone += $(" #phone").val(); comments += $("#comments").val(); prodotto += $(".item-name").text(); totale += $("#totale").text(); console.log(prodotto + " " + totale +" " + nome + " " + " " + cognome + " " + email +" "+ " " +" "+ phone +" " + comments); }); exports.nome = nome; exports.cognome = cognome; exports.email = email; exports.phone = phone; exports.comments = comments; exports.prodotto = prodotto; exports.totale = totale; //node js const { JSDOM } = require( "jsdom" ); const { window } = new JSDOM( "" ); const $ = require( "jquery" )( window ); const nodemailer = require("nodemailer"); const invioMail = require("./invio"); var nome = invioMail.nome; var cognome = invioMail.cognome; var email = invioMail.email; var phone = invioMail.phone; var comments = invioMail.comments; var prodotto = invioMail.prodotto; var totale = invioMail.totale; const transporter = nodemailer.createTransport({ host: 'smtp.gmail.com', // hostname secure: false, // use SSL port:25, // port host mail auth: { user: 'mailuser', // mail pass: 'pwuser' // naturally, replace both with your real credentials or an application-specific password }, tls: { rejectUnauthorized: false } }); const mailOptions = { from: 'mailuser', to: email, subject: 'Invoices due', text: 'Dudes, we really need your money.' }; transporter.sendMail(mailOptions, function(error, info){ if (error) { console.log(error); } else { console.log('Email sent: ' + info.response); } }); // error var resoconto = $(function() {

11th Jun 2020, 6:12 PM
Alessio Farroni
Alessio Farroni - avatar
5 Respuestas
+ 3
Alessio Farroni Can you share your code link so I can check later?
11th Jun 2020, 7:52 PM
A͢J
A͢J - avatar
+ 2
Alessio Farroni You have to put JQuery library above the node js file.
11th Jun 2020, 6:31 PM
A͢J
A͢J - avatar
+ 1
Alessio Farroni Yes and you can't defined $ as constant because JQuery already consists $.
11th Jun 2020, 7:07 PM
A͢J
A͢J - avatar
0
AJ Anant like var jequery =require('jquery') ?
11th Jun 2020, 7:01 PM
Alessio Farroni
Alessio Farroni - avatar
0
AJ Anant still don't work, tomorrow i Will do the upload on gist and repost the code
11th Jun 2020, 7:45 PM
Alessio Farroni
Alessio Farroni - avatar