James
James

Reputation: 57

How to call a node.js script inside html?

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

Upvotes: 0

Views: 410

Answers (1)

eminfedar
eminfedar

Reputation: 668

  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...)

Upvotes: 2

Related Questions