Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hopefully I'm not too far off the mark with what you're trying to do here. My understanding (cobbled together between this and <a href="https://stackoverflow.com/questions/17843787/using-global-config-variable-in-express-node-js-framework">your previous question</a> is that you would like something in the browser that upon click will retrieve some status information from an external API, which will then be displayed in the client. </p> <p>What I would recommend doing (based on the above assumption) is defining your desired function as something to be triggered by an HTTP request to the Express server, which can perform your function and send whatever you'd like from its process back to the client.</p> <p>In your server define (assuming your Express variable is <code>app</code>)</p> <p><code>app.get('/request', someFunction);</code></p> <p>In <code>someFunction</code> define what it is you'd like to do, how it relates to the request and response, and what to send back to the client. Express will expect the function to take request and response as arguments, but you don't necessarily need to use them:</p> <pre><code>someFunction(req,res) { //do whatever I'd like with aws or anything else res.send(foo); //where foo is whatever JSON or text or anything else I'd like the client to have to manipulate } </code></pre> <p>On the client, you would have a function bound to onclick that would make the request to that <code>/request</code> endpoint. This function could use AJAX or simply render another page entirely.</p> <p>This sort of organization also leaves display and behavior to the client, while the server deals with retrieving and manipulating data. This layout also resolves any concerns about require() statements on the clientside (which, while possible with things like <a href="https://npmjs.org/package/browserify" rel="nofollow noreferrer" title="Browserify">Browserify</a>, are not necessary and may make the code more confusing).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload