Sending Data Between Node And HTML

3👍

First of all:
Please provide more information about your client’s webpage and your node application! There are different ways to get what you want. On the one hand you can use template engines in your node application to pass data to your client webpage.

Frontend:

On the other hand you can do it by simply do an ajax request when loading the webpage. I recommend using jQuery for your webpage. Besides a lot of helpful features for developing your webpage, it provides some simple ajax-functionalities to easily set the xhr headers and manage the asynchronity.

If you managed to setup your webpage so far, so that you can use jQuery try this code:

$.ajax({
    type: "GET", // specify you request type here (e.g. "POST", "PUT", etc.)
    url: "/theURL" // modify the url according to your application logic
}).done(function(yourData) {
    // work with your data
});

Backend:

Since I don’t know how you setup your node application, I can’t tell you more about this side. Assuming that you are using the express server framework:

    // here goes the specified request type from above (e.g. app.post, app.put, etc.)
    app.get('/theURL', function(req, res) {
        var data;
        // Get your data from your database
        res.json(data);
    });

Leave a comment