0

I have website built by html5 and served by Apache, I have installed Nodejs on the same sever.

I want to use node mail to send email each time a html page visited, how can I make the html page to trigger a Nodejs file/program or module?

I just don't know how the HTML page can interact with Nodejs program on the server

Jonas
  • 121,568
  • 97
  • 310
  • 388

3 Answers3

0

You can use Ajax technology.

Using ajax, you can request an http request trigger your node server to do mail delievery.

Kit

TheOneTeam
  • 25,806
  • 45
  • 116
  • 158
0

Nodejs is a server side technology. How would you have done it using PHP or Rails? It's the same in principle.

You could for example expose a REST API to call into the server and send a mail, which could then be called from the javascript on the client.

James Bloomer
  • 5,212
  • 2
  • 22
  • 23
0

Apache and Node run as two different servers and two different processes.

As described by others, you could use client-side ajax to trigger actions between the two servers. You could use something like dnode that provides RPC (remote procedure calls) between two servers. As described on https://github.com/substack/dnode There are dnode implementations for perl, ruby, php, and java, so you can glue together all your backend processes swimmingly.

On the same server you could create a new process. For instance, using PHP you could use system or popen to call node. ie. system("node mail.js [args]"). Make sure to escape your arguments carefully. Here is a popen example: http://svn.php.net/viewvc/pear/packages/Mail/trunk/Mail/sendmail.php?view=markup

Note: I am not sure what advantages using node mail has over using the standard implementation in your apache stack (ie. using PHPjust call mail()). If you are looking for non-blocking there are options available in most cases: Send mail without blocking 'execution'

Community
  • 1
  • 1
graemec
  • 373
  • 3
  • 6
  • I don't use php or any server side scripting, it's just html5 pages and node on the server side as scripting language. – Fadi Samara Feb 13 '12 at 22:37