Unable to update local json file in React native app - json

My React Native app file structure looks like this:
/assests
/json
example.json
/components
view.js
I need to take input from the user in the view.js component and store it in the example.json file for future use. I tried using react-native-fs but could not figure out how to use it to get the absolute path of example.json and the relative path kept on throwing errors. If there is some other way to do this, it would be most appreciated.
Thanks in advance for the help!!!!

Found out what the problem was. I was trying to update files that are in the app bundle and forgot that they are read-only. So I copied the files from the app bundle to the document directory and is accessible from there. I can edit and delete from there.

Related

Can't Find JS file in Console

I am pretty new and I am trying to work with the GIPHY API, but I can not get my js file to be found in the browser. I have tried to create a whole new repo and I got the same issue. Can anyone help?
Here is my directory:
Image with error
Here is my HTML. Can anyone Help?
Folder structure
When I look in the console I get the message:Failed to load resource: net::ERR_FILE_NOT_FOUND
There is teh GIPHY sample code in the file so it is not empty.
Your path is not correct you need to point to the exact location your file is.
Try with ../js/main.js instead of js\main.js
For the standard way, you should move your index.html file in the root of the project and then point your js file like this js/main.js instead of js\main.js
If you can make your source to be just the file name likemain.jsalone
It will make you avoid the mistake of js\main.js thus solving the issue

How to Load CSV file in React Native

I want to download one CSV file in my React Native Project. I have put CSV file in assets folder in React Native Project, I'm using RNFS for fetching the same.
But when I console log RNFS.MainBundlePath it returns undefined value. Below is my Code to get the path from RNFS.
var mainBundlePath = RNFS.MainBundlePath;
var path = '/assets/Product.csv';
Any suggestions on this matter?
There you can user below library it will help me to achieve same thing in past.
Try csvtojson
you can Installation
npm i --save csvtojson
see the example given here

How to access json file in Angular4

I want to acccess data.json file in myservice.service.ts .
Can anyone suggest me how to achieve it?
Directory structure
myserivce.service.ts file
Getting error like this
Use URL like data.json and Put the data.json file in your src/ directory. It will work fine.
OR
Use URL like assets/data.json and Put the data.json file in your src/assets/ directory.
Two things.
The data.json file has to exist on the server hosting the web application.
The URL you provide $http is not relative to the service or component that is executing the request (or request chain). You have to specify the absolute url which would be
private _url = '/src/app/data.json';

Getting a path of accessed script in Dart

The aim is to create a config file for server-side Dart application, which can be imported as needed into scripts like so:
import 'Config/config.dart';
What is crucial for this config script however, is that it knows it's own location when being accessed with an import (not the location of the file accessing it). Currently it uses this line below to find the path:
final String ROOT_DIR = dirname(Platform.script.toFilePath());
However, this returns the file path of the file importing it and not the file that is being imported. This needs to be known purely for working out a relative path to the root folder, which will allow other absolute paths to be known in the config file (such as routes, controllers, and things), like so:
final String PUBLIC_DIR = join(ROOT_DIR, 'Public');
final String VIEWS_DIR = join(ROOT_DIR, 'Views');
What would be the best way of approaching this? I have seen this post: Get script path in Dart (analog __DIR__ constant in PHP) which is the same sort of situation, however I can't see a clean way of using relative paths to find the route folder.
Probably missing something really obvious, but can't see it at the moment. Any help would be much appreciated, thank you for reading.
This is not supported in Dart.
Maybe Mezoni found some kind of trick to get this information which he packed in his caller_info package https://stackoverflow.com/a/24880092/217408.
You can't rely on the path where the files are stored during development.
Currently it is only experimental but when you run dart2dart on your code, all or many parts of the code are inlined.

Reading files with Node.js from input file type selector

I am trying to select files using input file type and then upload them to dropbox using the dropbox Core API or saving it to a local folder using Node.JS readFile and writeFile methods. The problem is that most of these methods require the file path and all I have is the name of the file that is stored in the File object array and for what I have read browsers do not allow to get the full path for security reasons. I don't know how to go about this, can anyone help me solve this? Thanks!!