-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.

SupEldrix
  • 103
  • 1
  • 8

1 Answers1

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.

helloitsjoe
  • 6,264
  • 3
  • 19
  • 32
  • I do use a local host node server – SupEldrix Sep 15 '20 at 12:23
  • 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. – helloitsjoe Sep 15 '20 at 12:44
  • See this answer for more detail: https://stackoverflow.com/a/41726825/8852158 – helloitsjoe Sep 15 '20 at 12:45
  • 1
    oh really Good to know I'll try that out asap and thanks Yeah I used create-react-app – SupEldrix Sep 15 '20 at 12:47