M
M
M1sterSandman2019-04-04 15:47:41
JavaScript
M1sterSandman, 2019-04-04 15:47:41

How to get data from db and write it to js file?

Hello. I just can’t understand and find how I can get data from a database (for example, mongodb), and write this data to a js file, namely to an array of objects. I will use this file later in an application written in React (the application is already ready). Can you suggest a sequence of actions or suggest where to find a similar solution? I will be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
krka92, 2019-04-04
@krka92

1. We receive using AJAX
2. We write not in JS, but in JSON. From the right place This JSON is readable.

M
Maxim Fedorov, 2019-04-04
@Maksclub

You need to raise a simple backend:

  1. you need to deploy an HTTP server so that you can reach the desired route, for example, using Express JS
  2. make a handler for processing the route , in which the necessary data will be collected
    (for example , get it from MongoDB )
    In a JS application, you will already need to refer to this route and it will return the necessary data
    . For example, using: https://github.com/CharlesMangwa/react-data-fetch...
    To work fine later , you can make Express friends with Nginx so that it proxies requests: https://gist.github.com/tomasevich/a2fe588c451c5a1...
    But I can make a mistake, because I don’t work in this stack at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question