I have an electron app that acts as a tool to speed up game development. When a user opens the app they can begin importing assets and setting custom properties. I store these properties in nedb. The way I have my application set up, every page change the properties from nedb are fetched and are immediately reflected on the page. I need to save these changes in a file the app can load and it would be intuitive to use nedb since it loads database info from a file optionally out of the box. However in the instance a user opens my app and begins working without a file, I have no way to store these changes for later use. I have found no docs for exporting the database on the fly.
Related
I need to build a page builder where we want to drag and drop elements to a screen which become a config json object. Then I have to save that config object into a config.json file in the project folder (or somewhere where I can load it when re-rendering the app). We want live reload when editing the pages via this page builder.
The FE drag and drop app is built with React, and I can reach the point where I have the JSON object in memory.
How do you recommend me to do the architecture this for the BE side?
Is is possible to expose an API endpoint (with Express for example), and save the json file somewhere into the React App "/src" folder? or I can edit only files in "/public" folder?
What if I refactor my FE React app into a Next.js app? If Next is rendered in the server, does it mean that I can do the config file editing just before it gets rendered?
Is it better to create an independent Express App where I save all the config.json files? and then exposing them via API endpoints both for editing and reading?
Thanks in advance!
From your question I see that you are developing a app similar to wordpress where the users can easily create a page using drag and drop of elements. So here a configuration is need to persist the placement of elements.
I read all the three approaches mentioned by you and it seem the third approach will help you. You can run a express app and use a db to store the config setting as I find storing it in the file is not a good practice. Once the editing is complete you can make an api call to post the data to db and similarly while reading you can pull the data from db using api call.
We are developing an app using Electron and Vue.js. In our app we are using NeDB for temporarily storing JSON documents after having received (and decrypted) them from a Firebase Database. A requirement of the app is, that the decrypted data stays in memory and is not saved to disk during the user session. Therefore we use NeDB with the inMemoryOnly flag.
Our goal is to show reports for contents of the database in a different BrowserWindow to print / save them as PDF.
We tried to initialize the database using a global variable, but unfortunately the database content was empty. Is there another possibility to access the database from within a different BrowserWindow?
I was viewing this website which has an awesome customized search options panel. I was wondering how can we remember the state of checkboxes and textfields when the query returns the results and HTML page renders. Take this page for example, it saves the user's selected options when the page refreshes. I want to implement this feature in Node, Mongo and Express.
There are two ways you could do this. If you want to persist the options long term, when the user selects something, you'd send a POST or PUT request to the server and have the server save the settings in Mongo. The second option (which I think is a better choice here) is to just use local storage on the client. See this documentation for how to use local storage.
With local storage, everything is client-side, so you don't have to worry about the latency and complication of dealing with the server. The user will have their options saved on that computer until they go into their browser settings and delete it.
Edit: I think what you're looking for is session storage. This is similar to local storage but it gets reset when the browser window closes or the session expires.
I developed a small node.js app in which I can configure conditions for a custom javascript file, which can be embedded in a webpage, and which modifies the DOM of that page in the browser on load. The configuration values are stored in MongoDB. (For sake of argument: add class "A" to DOM element with ID "B" )
I have difficulties to figure out the best way to serve requests / the JavaScript file.
Option 1 and my current implementation is:
I save a configuration in the node app and a distinct JavaScript
file is created for that configuration.
The page references that file which is hosted and served by the server.
Option 2 and where I think I want and should go is:
I saves a configuration (mongodb) NO JavaScript file is created Pages
a generic JavaScript link (for instance: api.service.com/javascript.js)
Node.js / Express app processes the request, and
returns a custom JavaScript (file?) with the correct values as saved in mongodb for that configuration
Now, while I believe this is the right way to go about it, I am unsure HOW to go about it. Any ideas and advise are very welcome!
Ps: For instance I wonder how best to authenticate or identify the origin, user and requested configuration. Shall I do this like: api.service.com/javascript.js&id="userID" - is that good practice?
Why not serve up a generic Javascript file which can take a customized json object (directly from mongodb) and apply the necessary actions? You can include the json data on the page if you really need to have everything embedded, but breaking up configuration and code is the most maintainable approach.
I'm building a web application based on backbone.js as the frontend and node.js as the backend.
I am looking for best practices on loading and saving the application settings/configuration a backbone/node environment. The idea is to allow an admin user to view/edit the settings, and of course these settings will silently be loaded when any user is accessing the application through the web.
I was thinking of creating a backbone model called 'settings', which will be loaded once the application starts. Then add a settings view where admins can view and edit at will. Not all the settings will be pre-loaded, only when the admin tried to access them (for eg. settings that are relevant for the backend will only be shown in the admin edit page, and not pre-loaded on application start)
Note: These settings will be saved in a MongoDB document.
How do you guys manage your web application settings/configurations?
Any data that is going to be accessible through the client and retrieved from your database should be represented by a backbone model. Your intuition of creating a 'settings' backbone model will allow you to display the data retrieved from your MongoDB backend. Then, when the settings are updated in your view, you can save the backbone model, which will in turn update the settings in your db.
Since you are dealing with settings/configurations that can affect your application, you just want to make sure that you do correct validation on anyone trying to access that specific page.