Pass nodejs variable (Express) to Javascript [closed]

-1

Suppose I have a database in mongodb, in which I can store some information with .save () but now, I want to retrieve that information and pass it to the client, for which I use findOne () to acquire the desired data , that data I want to pass to the client through a variable. I've searched on Google but I get solutions using engines and the truth is that I use pure HTML. Anyone give me the green light? How do I pass variables from Express to client Javascript and then display them in the view?

    
asked by Diesan Romero 21.12.2018 в 05:00
source

1 answer

0

There are two ways to send data from the server so that it is displayed on the client:

  • Using your node server as a REST API that returns an exchange format as JSON
  • Skip what you get from mongo and send it to a template engine template engines
  • The one you choose will depend a lot on the way you are doing your application, the first option is used for the SPA (Single Page Application), the second would be for a traditional website (as you would with Laravel, Rails or Django ) where you pass the information to the template, it gets the data and translates it into the html.

        
    answered by 21.12.2018 / 16:20
    source