Answer the question
In order to leave comments, you need to log in
How to execute a function with a button in Node.js?
I want to ask for help. I am new to node.js.
For example, I made a web server as described here: www.nodebeginner.ru . Everything is working.
But there was a need, for example, in the start function to add a regular button that will launch another function.
This is about the same as it is written in the JS tutorial
<input type="button" onclick="countRabbits()" value="Считать кроликов!"/>
'<input id="b1" value="Нажми меня" click="testfun" type="button"/>'+
Answer the question
In order to leave comments, you need to log in
You are confusing something. What you need to do is normal javascript in the browser. Node.js has nothing to do with this, because it runs on the server, not the client.
Hello.
No, I'm not confused. I also need the function to be executed on the server (roughly speaking, it calculates x + y). But the user could start these calculations with the push of a button. At the same time, without leaving the current page.
If you want without reloading the page, there are several ways:
1. Do it yourself using AJAX
2. Use some ready-made rpc module (RPC-remote procedure call, remote procedure call), for example https://github.com/substack/ dnode (in general, for node RPC, see modules here - https://nodejsmodules.org/tags/rpc )
3. Either manually using sockets (for example, socket.io)
4. Use for node instead of express.js some framework that was originally it can for example meteor.js
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question