Where can I Store json file for use after building the app in node-webkit? - node.js

Is there any specific folder where I can store my files so that the app can use it later after building? Like Meteor has a private folder, is there any folder for node webkit?

As far as I know there is no predefined path and it is not needed. You can access any file with relative path from current dir. Just do not forget to add it into final build.

Related

Copying files/folders to Electron Dist folder

Long story short:
I need to copy some files/directories over from my src folder to my dist/resources folder. Is there any way I can 'automatically' copy these files/folders over during packaging? I am using Electron-packager.
Long story:
I have a couple of folders containing JSON files that need to be read and copied over to a certain user directory. These are all done when I mount a certain component.
I use readFileSync() and using path.resolve with __dirname - but this generates an error since my relative path is different when I am running the packaged app (inside dist folder). Error is it cannot find my JSON file in dist/resources/config/settings.json. Also tried to check content of my app.asar but can't seem to find it there.
So my working workaround is to copy the directory/files over from my src folder to my dist/resources folder.
But this is kind of hacky and prone to forgetting. Is there any way I can 'automatically' copy these files/folders over during packaging?
I've seen a lot of questions like this and I've never really understood them. Maybe your project structure is very different than mine (below)?
Everything that is within my "app" directory is included by electron-packager (or electron-builder – I use both) and so it's all available when the app i packaged. In my case I have some Excel templates which the user can opt to save to disk but I could just as well create a directory and copy them there at first launch (haven't tried this but assuming permissions are ok I don't doubt that it will work). Maybe that is less "clean" than having a separate resources folder?
That said, I have seen this: Electron - How to add external files?

How to configure the server in angular to get files?

I just run the ng serve command and go to the server. But if I drop the file house.jpg into the src folder, then when I access the address http://localhost:4200/house.jpg then I don’t see this file, the main page of the project opens.
I did not find anything about it in the official documentation, I ask the help of professionals
You need to follow the Angular Structure Guide. As said above, you need to put your images and other files you want to use frontend-side in the assets folder.
The assets folder contains image and other asset files to be copied as-is when you build your application.
Notice you can create any folders you want in assets if you want to order your files.

Create desktop folder electron

I'm using node fs to create a directory and then watch it in my electron app. Users can then use that directory to upload documents. I use chokidar to watch the directory for documents. This all works locally; fs creates the directory inside my app folder. I can drag and drop files in, everything works.
This doesn't work, however, when I deploy the app to windows. I've searched the filesystem and cannot find where this folder was created.
What I'd like to do is create the folder on their Desktop. It would be even cooler if I could react to movements of the folder (e.g. the user moves it to Documents).
Is there a way to
Create the folder on their desktop (both osx and windows)
Listen for when the folder has been moved to another location.
Thanks!
Update
Found a way to find their desktop directory
const dir = Path.join(require('os').homedir(), 'Desktop/whatever');
Is there a way to do number 2?

Electron: Share Files Between Different O.S Packages

I've created an Electron app and build packages for Windows and MacOS using electron-packager. The app data is stored in a JSON file inside the resources folder and i'm using fs to perform file I/O tasks in the app.
What i would like to do is store the JSON file in a folder that could be accessed by both packages (Win and Mac). This way my client could use both versions of the app and the data source will be the same, thus, the data always updated.
Since i'm a Electron newbie, is there a way to "merge" both packages and share the same data file?
Thanks to #kevingelion and #revln9 from the Slack Electron discussion, i was able to solve my issue.
All i need to use is getAppPath() and from there go to the parent folder where the data file is located:
var app = require('electron').remote.app;
resourcePath = path.join(app.getAppPath(), '../../../db/'); //shared folder

Regarding user settings - whats the purpose of the assets folder?

I want to find the correct place to save my user settings for my uwp app. I know there exists:
local: Data that exists on the current device and is backed up in the cloud
roaming: Data that exists on all devices on which the user has installed the app
temporary: Data that could be removed by the system any time the app isn't running
-localcache: Persistent data that
exists only on the current device
I can access the above places with ApplicationData.Current. Which are located somewhere in C:\Users\bla\AppData\Local\Packages\1e7e-94a6-4235-a0c5-9b143f8b_8webbwe
The project also contains a Asset folder, and I can't find a good source which tells me where the folder is located when the app is installed (not in developer mode).
Some developers place there settings into the asset folder. Why? What's the advantage? Is there also a file size limit like for ApplicationData.Current ? When deploying a settings folder into the asset folder will it be available for all user which installed my app? Any background informations regarding the asset folder are appreciated.
Settings files are most appropriate in the ApplicationData folders or ApplicationData.LocalSettings or .RoamingSettings See Store and retrieve settings and other app data
The assets folder is purely a convention. The "assets" name is not special other than to suggest what types of files go in the folder. It is just a useful way to organize the application package to have a place for assets (images, etc.) that are used in the app.
When the app is installed the assets will be in the Package.InstalledLocation directory and can be addressed with an ms-appx:///assets/ URI. Typically this will end up somewhere in \Program Files\WindowsApps\.
Putting a settings file in assets would be a bad idea as the InstalledLocation is read-only and as settings are user data.
There is no hard size limit for files in ApplicationData folders, although if too much data is stored in RoamingFolder then it won't roam. The files will still be available locally.

Resources