trouble using express.js
i have a js file that im using express.js code using the nodemailer module. What im trying to do is have a user enter their details in a form and when they press a button i receive details that they entered as an email, but i dont seem to understand what the problem is. in my browser im getting this error
i did some searching and it said the browser cannot understand node.js files or something like that, Does anyone know what the actua problem is
8 Replies
It looks like an error in the syntax you used to import something in the first line of your app.
If you share the first line the problem might be there.
this is the js
Can I get your package.json?
.
try using es modules instead
check how to use es modules in nodejs
In your original question, I am confused about what you mean by error in your browser. You are supposed to use node in a terminal to run this script and not a browser
Browser doesn't support
require
statementsHi do you mind sharing your front-end code for this page.
How are you executing js file? What is its name? Your package.json file hints at a file named app.js
If so, in your terminal (not a web browser) either of the following should start your express js server:
node app.js
…OR…
npm run start
if you get a “module not found “ error. Trying running’npm install’ first
Once the server is running , then you can invoke your web server endpoint POST http://localhost:3000/aubmit-form