-1

Anybody who's knowledgeable using NeDB?

import React from "react";
const Datastore = require("nedb"),
  database = new Datastore({ filename: "./database.db", autoload: true });

database.loadDatabase();

const App = () => {
  return <div>Hello</div>;
};

export default App;

I just want to load an empty database file.. I tried multiple ways of picking the file path but it doesn't seem to appear.

1 Answer 1

1

Creating a new database file won't work in the browser, you'll have to run that on the server to create a file:

On the server:

const Datastore = require("nedb"),
  database = new Datastore({ filename: "./database.db", autoload: true });

On the client:

import React from "react";

const App = () => {
  return <div>Hello</div>;
};

export default App;

On the client, you can use nedb to create an in-memory DataStore, but it won't be persisted to a file.

Sign up to request clarification or add additional context in comments.

4 Comments

I do use a local host node server
But is this code running on the server, e.g. in an Express app? It looks like client side code, unless you’re server rendering React. If you’re using something like create-react-app or webpack-dev-server, you’ll need to have a separate server running to persist the DB.
See this answer for more detail: stackoverflow.com/a/41726825/8852158
oh really Good to know I'll try that out asap and thanks Yeah I used create-react-app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.