简体   繁体   English

在服务器上运行js代码

[英]Running a js code on the server

I have a third-party javascript code which communicates with their web server and which I want to run periodically on the server . 我有一个与它们的Web服务器通信的第三方javascript代码,并且希望在该服务器上 定期运行。 I'm not that familiar with NodeJS so that's why I don't know exactly wether it'll help me or not, although I've read some articles about that topic. 我对NodeJS并不那么熟悉,这就是为什么我不确切知道它是否对我有帮助,尽管我已经阅读了一些有关该主题的文章。 The task is run that script on the server exactly as it were in a browser on the client. 该脚本在服务器上运行的脚本与客户端浏览器中的脚本完全相同。 Is it possible to do with NodeJS? 是否可以使用NodeJS?

The task is run that script on the server exactly as it were in a browser on the client. 该脚本在服务器上运行的脚本与客户端浏览器中的脚本完全相同。 Is it possible to do with NodeJS? 是否可以使用NodeJS?

Very nearly, yes. 非常接近,是的。 What you're looking for is a "headless browser" with a JavaScript API and/or NodeJS module. 您正在寻找的是带有JavaScript API和/或NodeJS模块的“无头浏览器”。 Specific recommendations are not what SO is for, but that's the term to search for, and I'll note that both jQuery and Sizzle projects (closely related) use PhantomJS . 特定的建议不是SO的目的,而是要搜索的术语,我会注意到jQuery和Sizzle项目(密切相关)都使用PhantomJS (I haven't used it directly, just as a byproduct of contributing to projects that do.) It's not a NodeJS module (it has to run in its own process), but you can launch it from Node as a project and then interact with it. (我并没有直接使用它,只是作为为所做的项目做贡献的副产品。)它不是NodeJS模块(它必须在自己的过程中运行),但是您可以从Node作为项目启动它,然后进行交互用它。

Then you load whatever assets you need into the headless browser, including the JavaScript you need to run. 然后,将所需的任何资产(包括需要运行的JavaScript)加载到无头浏览器中。

Needless to say, you need to really trust the source of any code you receive and run on your server. 不用说,您需要真正信任接收到并在服务器上运行的任何代码的源。 :-) :-)

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

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