score:0

okay, i dont access the lowdb by frontend. i use axios to send a request to my node/express backend and respond with the lowdb-data. requires you know how to interact with a react frontend and a node/express backend on different ports. i dont let express render my react-app... looks something like this and axios as a dependency in the package.json + import axios from 'axios':

export default class status extends component {
  constructor(props) {
    super(props);
    this.state = "";
  }
  componentwillmount() {
    axios.get("http://localhost:4000/dbuserauth").then((res) => {
      let authstate = res.data;
      if (authstate) {
        this.setstate({ authstate });
      }
    });
  }

this sends a request to my node.js/express backend which runs on port 4000. the frontend runs on 2000. the backend can look something like this:

server.get("/dbuserauth", (request, response) => {
  function resauthdata() {
    let array = [];
    const dbuserauth = db.get("userauth[0]").value();
    const dbchatidfound = db.get("userauth[1]").value();
    const botactive = db.get("userauth[2]").value();
    array.push(dbuserauth, dbchatidfound, botactive);
    response.send(array);
  }
  resauthdata();
});

hopefully someone needs theese snippets. best regards


Related Query

More Query from same tag