简体   繁体   English

expressjs服务器上的HTML按钮运行node.js脚本

[英]HTML button on expressjs server run node.js script

I have a button in HTML: 我有一个HTML按钮:

<button id="save" type="button" onclick="save()">Save</button>

and in javascript I want it to run something in node.js, something that's not client side. 在javascript中,我希望它在node.js中运行某些内容,而不是在客户端运行。

So something like this is what I am looking for: 所以我正在寻找这样的东西:

function save() {
    //run script from server
}

And if this script MUST be ran as if I was typing node script.js 如果必须像我键入node script.js一样运行该脚本

The reason the script has to be ran as if I was typing it was because it's saving a file to the node.js server, a json to be exact, and that file must be on the node.js server for my application. 必须像我在键入脚本一样运行脚本的原因是因为它正在将文件保存到node.js服务器(确切地说是json),并且该文件必须在我的应用程序的node.js服务器上。

So you really can't execute a server-function from the client side, but you can maybe send a post-request and call the function on the server side, or you can use sockets to communicate with the server. 因此,您实际上不能从客户端执行服务器功能,但是可以发送后请求并在服务器端调用该功能,也可以使用套接字与服务器通信。 Either way, it would be horrible security-wise, if you would be able to interact with the server on that way. 无论哪种方式,如果您能够以这种方式与服务器进行交互,那么这在安全性方面都是可怕的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM