T
T
taki1542020-02-25 13:01:16
API
taki154, 2020-02-25 13:01:16

How to send subrequests in express.js?

Hello!
I am building the first application on the MEAN stack, I made a simple CRUD-api, which on app.get () gives data from mongo db in json format.
Now I'm fastening the template engine and I can't understand the fundamental point:

here is the index page (no data yet).

app.get('/', function(req, res) {
  res.render("index", {});
});


a json object with data is given along this path.
/api/backups

I can't figure out how to "make friends" of the display with the data, so that on request for "/" you can get a web face with data from /api/backups.

Guessing - either do something with the routes additionally (what?), Or send an ajax request..

I did my work according to this tutorial

Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
ranftldieter, 2020-02-25
@ranftldieter

If /api/backups is located on the local machine, it is easier to make a function with a request to the database and process it when switching to index. If you want to get data with a request, then you can use the request package, for example

I
ince, 2020-02-26
@ince

Either copy the code from /api/backups to index (or move the functionality into a separate function and call it in two places)
Or make an ajax request to yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question