Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

create file json or text in angular

i am trying to create a file .json or .text in angular and put it in path : /assets.

after searching for a while all result is to get data from file:

we can get data from file using this methode:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this.httpClient.get("assets/data.json").subscribe(data =>{
  console.log(data);
})

But how to post and create a new file data.json and put it in assets?

>Solution :

Browsers aren’t allowed to simply write to files to the server. If that was possible, the Google homepage would be vandalised 30 times a second.

You need to write a web service (in the programming language of your choice, which could be JavaScript or TypeScript if you arrange to have a server on which you can use Node.js).

You probably want to write the data somewhere other than assets (which sounds like a directory that is part of the built Angular application and not a user data directory) and you probably should be using a database rather than using JSON file (databases are efficient and deal with simultaneous writes easily) — your web service can have another endpoint that reports the contents of the database as JSON.

Once you have a web service, then you can make a POST or PUT request to the URL for it using @angular/common/http as described in the Angular guide.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading