None
None

Reputation: 5670

call Nodejs function from url

I want to execute a function inside a remote URL. I know the page URL where the function is and I know the Function name too. The server-side application is built on NodeJs Express. And the function itself look like this

    function executer(param1, parama2){
    //logic
    return true;
}

Is there any way to achieve this?

Upvotes: 0

Views: 1057

Answers (2)

JSEvgeny
JSEvgeny

Reputation: 2750

You can use for example an AJAX call to trigger an endpoint on server like this:

$.ajax({
  url: "/remoteservice/executer/",
  type: "get",
  data: {"param1": "param1","param2":"param2"}, 
  success: function(result){
    alert("Job is done");
  }
});

But you need to know the endpoint(url) and the method that it waits(get, post or whatever)

Upvotes: 1

Zeeshan Afzal Satti
Zeeshan Afzal Satti

Reputation: 440

If it is some API. Then you can use any node module for request like request or node-fetch. First is for callback and second for promises based. Examples are listed in modules description.

Upvotes: 1

Related Questions