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
Source: stackoverflow.com
Related Query
- Pattern for a React component with access to lowdb
- How to test style for a React component attribute with Enzyme
- How to specify function parameters for React component callback with TypeScript?
- How to access state when component unmount with React Hooks?
- How can I search for a component with specific key in React Developer Tools?
- Access React component from this.props.children with react-router
- Is it possible to access the current route component with React Router
- Access to store.dispatch in a saga for use with react router redux
- Styled component with access to React component state?
- Using the same component for different Routes with React Router
- lodash , convert string from svg circle (properties and values separates with space) to object for spread in react component inline
- Create flowtype for React component with static fields
- Access function of component wrapped with HOC in React
- Access data already fetched with react query in other component
- How to use Jest for testing a react component with localStorage?
- How to pass input values from a child Form component to the state of its parent component for submission with react hooks?
- How to define an interface for React function component with defaultProps without throwing missing type error?
- Strategy pattern with React component
- What type should I use for a React component with arbitrary properties?
- How to forbid children for a React component with typescript?
- Waiting for React component state to update before testing with Jest
- How to mock React Context for testing component with jest
- Issue with async value for React context not available from child component
- Syntactic Sugar for passing React props with the same key and value into component
- How to access param in parent component with React Router DOM
- Timer/Counter for react component - value remains 0 after increasing it with setInterval()
- React Router - Path with :id is not working correctly for component wrapped by HOC
- Mock a custom service with jest and enzyme for a react component
- Working example for Graph Toolkit using SharePoint spfx, React and Get component with template
- route to different component for similar routes with react router
More Query from same tag
- SetTimeout and For loop
- How can I map this join data in React JS
- Set images state to Flickr API Response
- Yup and react-hook-form: how to create conditional mandatory fields in a form?
- How i can use the handleSubmit inside my component?
- Formik and arrayField integration with material ui
- Migrating react-router v3 to v4
- Updating getDerivedStateFromProps to functional component
- Any way or solution to convert the string data from JSON API to int in js?
- ReferenceError: WebSocket is not defined in client side typescript react application
- React Child Component Not Rendering
- Debugging url in javascript
- The current testing environment is not configured to support act(...) - @testing-library/react
- Formik javascript syntax
- Resetting form fields to initial state in React
- Make a React table sortable alphabetically
- Reverse a transition on props change with styled-components
- Using useContext in React doesn't give me the expect data
- How do I get typography theme defaults to apply to regular tags with Material-UI?
- setState works but redux store update doesn't
- React Typescript: Pass value from child to parent
- I want to keep the file upload optional but the form is not submitting if file is not uploaded
- DefaultValues of react-hook-form is not setting the values to the Input fields in React JS
- Cannot change background color with OnClick
- REACT router: route component with multiple same-type components
- Fetching data in react returns "undefined" at first time
- How can I use "home" state within "global" reducer?
- Send data from function component to parent component
- selecting child react component under div is not working in app.jsx file
- React Styled Components - transform scale with props