简体   繁体   English

如何从本地触发 node.js 代码?

[英]How do I trigger a node.js code from local?

I would like to get info from an app and process it using node.js. Can I write the script and have it locally and trigger it using some apps like mule api?我想从一个应用程序获取信息并使用 node.js 处理它。我可以编写脚本并将其放在本地并使用 mule api 等应用程序触发它吗? or I should use some server like AWS to deploy the node.js code?或者我应该使用像 AWS 这样的服务器来部署 node.js 代码?

Set up an HTTP server with node, there are plenty of ways to do that (For example, the built-in http module or expressjs ) then send an HTTP request to it using the Fetch API (assuming we are talking about a browser communicating with it).使用节点设置一个 HTTP 服务器,有很多方法可以做到这一点(例如,内置的http模块或expressjs )然后使用Fetch API向它发送 HTTP 请求(假设我们正在谈论与它)。

About deploying it - heavily depends on your preference and needs, but that shouldn't change how you communicate with it.关于部署它——在很大程度上取决于您的偏好和需求,但这不应该改变您与之沟通的方式。

You could technically, but you should always let the server listening for some events on your machine, which is not ideal if you don't own a server.你可以在技术上,但你应该总是让服务器监听你机器上的一些事件,如果你没有服务器,这并不理想。 A better solution would be to deploy your script and trigger it in the way that it's more convenient to you.更好的解决方案是部署您的脚本并以您更方便的方式触发它。 It may be an HTTP request for example.例如,它可能是一个 HTTP 请求。 AWS is great, but if you don't want to spend too much time configuring stuff I'd suggest Heroku. AWS 很棒,但如果您不想花太多时间配置东西,我建议您使用 Heroku。

Can I write the script and have it locally and trigger it using some apps like mule api?我可以编写脚本并将其放在本地并使用 mule api 等应用程序触发它吗?

The blurb for Mule API says it supports on-premise systems, so yes. Mule API 的宣传语说它支持本地系统,所以是的。

or I should use some server like AWS to deploy the node.js code?或者我应该使用像 AWS 这样的服务器来部署 node.js 代码?

That's a matter of opinion.那是见仁见智了。

Using cloud hosting will:使用云托管将:

  • Save you from having to maintain the hardware that it runs on (including such things as making sure the computer doesn't get switched off)使您不必维护运行它的硬件(包括确保计算机不会关闭等事情)
  • Make security for the app more complicated.使应用程序的安全性更加复杂。

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

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