How to use data directory in react js?


#1

Hey guyz,

I have asked question Previously but doesn’t get any answer, please help as I need to complete task, what i have done so far is that I have used /data directory and used nedb database, but it is not stored in data directory, i-e when app update data is remove from device. I am using reactjs starter package.


#2

Hi @faraz, could you tell us a bit more about what you’re doing? Are you using a docker-compose.yml or a single dockerfile? could you share the relevant parts of your code/Dockerfile? how are you setting up the nedb inside /data?


#3

Thanks @pcarranzav for reply.
I am not using any docker file, My application has only one file with “Dockerfile.template” name, I have not much more idea of docker file that’s why I have not used it in my application. I have learnt about docker but doesn’t understand about it.

I am initializing nedb with

var filename = ‘/data/DB/DbName.db’;
var db = new Datastore({ filename: filename });

If docker file is needed then please give me some hint how I can used it in my application, as I have not idea how to use docker file?


#4

@faraz having a Dockerfile.template is fine - could you share what it looks like?

Is new Datastore() supposed to create the /data/DB folder if it doesn’t exist? Or are you creating it somewhere else?

How exactly are you pushing the update (git push? balena deploy?), and how are you checking that the data is not there after the update?


#5

Also, are you moving the device between applications? (Cause that would delete the old data)

What OS version are your devices using?


#6

@pcarranzav docker file template is exactly same as in this file.

 Is new Datastore() supposed to create the /data/DB folder if it doesn’t exist? Or are you creating it somewhere else?

I am not sure whether it is created this folder or not, but when I am running it is running OK, seems like it is creating folder automatically, when it dooesn’t exist. I am using same folder for creating database. My issue is it is Run Ok when there is no update or patch been pushed, when I pushed any patch, All data is removed from device.

How exactly are you pushing the update (git push? balena deploy?), and how are you checking that the data is not there after the update?

pushing update by git push . As i say earlier that, when I pushed any patch my application doesn’t find any DB on that path which I have set, once I created DB again, It is working every time, until any patch is been pushed.


#7

I am using one application for all of my devices, I only update application through git, via git push.

OS version used in all devices is balenaOS 2.26.0+rev1


#8

Hey @faraz, without seeing more of your application I’d have to assume that the database is being created on the contianer filesystem. This would expain why the file is removed on an update, as the container filesystem is destroyed on update (the /data directory is not part of the container filesystem, and is instead a docker volume so this should persist).

My first guess would be that the Datastore class does not accept a filename parameter? Can you link to the module that provides this function?

My other guess would be you’ve added a basic docker-compose file which does not create or bind any volumes - but again without seeing your code I can’t really say for certain.


#9

Thanks for reply. @CameronDiver

I have given /data path so how it is insert in container file system?

I have get code from nedb official github page

// Type 2: Persistent datastore with manual loading
var Datastore = require('nedb')
  , db = new Datastore({ filename: 'path/to/datafile' });
db.loadDatabase(function (err) {    // Callback is optional
  // Now commands will be executed
});

I this code it is saying that filename with path.

I previously answer the question about docker-compose, that I am using this file for docker. As I have not idea how to use docker, I have not implement any docker file.