I have created properties file in other directory of my computer. I want to read the data from that file and display it. So can anyone please suggest me, How can I achieve this.Thanks in advance.
-
3what kind of data? – mav-raj Nov 21 '19 at 10:40
-
check `properties-reader` npm package – Golak Sarangi Nov 21 '19 at 11:27
-
@mav-raj Thank you for the response. The data is title and paragraph, it is stored in key value format. Like example: about.title = Mission about.para = information about the mission. and this file is stored in other directory of the computer.Is it clear info. – Manoj L Nayak Nov 21 '19 at 11:46
-
@ManojLNayak so basically its a json file, right? – mav-raj Nov 21 '19 at 15:54
-
@mav-raj, its not a json file! it's a properties file. Actually I had stored the content for AboutUs page in .properties file outside of my application, trying to read the content and display it. – Manoj L Nayak Nov 22 '19 at 07:00
3 Answers
From what i understand, you have a properties file on YOUR computer and you want to read that file from reactjs app. This is not possible as front end is not allowed to directly access user's hard disk. This would be a big security flaw. This is because the front end part runs on the client side.
Consider a situation where you have written code to read file from desktop. Then your app would be able to read the desktop files of ALL USERS who use that app. That's why you always see an upload button when you have to choose a file to read. The file is first sent to server side and then processed.
Since reactjs runs on client side, it is better to maintain a server and make an API call to it to fetch the data. Or you can hard code it in react app itself if it isn't sensitive info.

- 608
- 7
- 20
On front-end side - You can't and You should not be able to because it'd be a huge security risk. Do not try to solve it on the client side. Try to think about a back-end solution after uploading that particular file to the server.
On the other hand - why are you trying to keep a file, which is logically connected with the app - outside of the repository ?

- 1,607
- 9
- 25
-
Thank you for the response. If the content stored in a file, then it would be easy to make changes in future as per the requirement. – Manoj L Nayak Nov 22 '19 at 10:03
-
I understand. Anyway - configshould not be stored outside of the repo. If the config contains some sensitive data - you need to solve it on the server side. If it's not sensitive - keep it in the project folder – AdamKniec Nov 22 '19 at 10:08
-
Actually data is not sensitive, so I'll keep that file in the project folder itself. Thanks for your quick response. – Manoj L Nayak Nov 22 '19 at 10:15
-
Since its not clear what you are trying to achive,
Situation 1. You developed a react app for users, which is trying to read a user's file on his computer.
This is not possible as reactjs is a front-end library which can access the resources limited to browser only. You just can't read someone else's files.
Situation 2. The file is a part of you project which is in different directory.
So just put your file inside the your project directory, and since it is a properties file then this is how you can import it inside your project.

- 751
- 1
- 7
- 20