0

Please excuse my ignorance.

I'm able to send an email with the following command from my apps directory via the command prompt.

node send-email.js

Though I'm having trouble executing the script from inside my html page, for example via a button click.

What are my steps to accomplish this?

Thank you

1
  • node is a system command. Your browser for security reasons has no access to your system. Maybe you should place this send-email.js on a web site, and call it via an API call when button click. Commented Oct 20, 2019 at 10:16

1 Answer 1

2
  1. NodeJS runs on server-side, HTML files are running on client's Web Browser.
  2. Because of that, you can't run a Javascript code which exists in the server-side at the client-side just because they are both Javascript.
  3. If you want to send an email by clicking a button in a web page, you can send a POST request to the NodeJS (or PHP, or Asp.NET...) server to make it send an email.

There are some nice webserver frameworks for NodeJS called express.js, koa.js and etc. You can use them to receive http requests from clients and process them. (like adding an item to a database, making an user logged in, and all kinds of server stuff...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.