在我的Node服务器上收到http发布请求时执行脚本

Executing a script upon receiving a http post request on my Node server?

本文关键字:请求 脚本 执行 布请求 服务器 Node 我的 http      更新时间:2023-09-26

我有一个节点服务器,它从我的chrome扩展接收http POST消息。

javascript:

  function RecieveMessage(req, res) {
    console.log("got the message"
     }

我想知道当ReciveMessage函数接收到消息时,如何执行我的节点服务器上保存的另一个JS文件?最好的方法是什么?

除非我误解了,否则应该这样做:

var otherFile = require('./otherfile.js');
...
function RecieveMessage(req, res) {
  console.log("got the message");
  otherFile(args);
}

您的"otherfile.js"应该公开这样一个主要函数:

module.exports = function (args) {
  // Your code goes in here
};
相关文章: