If I use a json file stored in one of my GitHub repos as a mock backend, I know how to fetch and read all the data. Is it also possible to edit or post new data to this json file? Would an alternative mock backend like Mocky.io be a better solution (to achieve full CRUD)?
I think you could store the information inside csv files or somehting like that, you would be recreating a database engine as MongoDB & create your own reader to find the info, or you could store the users info using local Storage,
However this would make your app very limited.
Here's the link for the documentation of local storage
https://developer.mozilla.org/es/docs/Web/API/Window/localStorage
Well if you want to try out CRUD operations you can use free JSON APIs like http://jsonplaceholder.typicode.com/ or
https://mockfirst.com/
where you can create, read, update and delete data using various api end points. It is better to go this way first then you could move on to updating a JSON file.
(UPDATE)
You can use https://jsonbin.io/
Here you can place your own data and use it as an API.
Related
I have been using MongoDB atlas for a while now, and have decided to start hosting the database locally. After creating a new collection, completing all the standard steps, with no errors, and adding a new object with mongoose, I don't see the collection in my data/db file. Is there a different place where I should be looking to find plain text, as such in Atlas?
Like many databases, MongoDB does not store data in plain text files. It does use files but these files are binary and generally not usable directly by users.
Atlas does not provide filesystem access in any event, so whatever files it does use you won't be able to retrieve.
To extract your data, use a tool like mongodump.
Have a look at this page from the MongoDB docs.
It shows how to export the data as json or csv from Atlas
You can take the mongodump of your data from the atlas cluster and later on you can mongorestore it to your local deployment.
mongodump : https://docs.mongodb.com/manual/reference/program/mongodump/#bin.mongodump
mongorestore : https://docs.mongodb.com/manual/reference/program/mongorestore/#bin.mongorestore
I have a JSON file 'DealerList.json' and I can access it from my app by importing it using
import DealerList from './json/DealerList'
let tasks = DealerList;
The tasks here contain the JSON and I can easily access it.
Is there any way by which I can update the JSON back like if I update the values OR if I delete the values. I have also tried require("fs") but that too is throwing error.
The JSON file is present in a folder called json in the React App.
No, and this is a good thing. You do not want any web browser to be able to come along and rewrite files on your HTTP server.
Write a web service which will read and update the data based on HTTP requests (with appropriate authentication/authorization to stop undesirables from changing the data). Then interact with it via XMLHttpRequest / fetch / an abstraction library wrapping one of them (like axios).
(Or use localStorage if you want to store the data on a per-browser basis rather than shared between visitors).
I made a game with javascript using this tutorial as a base: http://html5gamedev.samlancashire.com/making-a-simple-html5-canvas-game-part-3-drawing-images/
How do I get it to write the data from the item counter (var itemCounter = 50;) to a text file named savedata.txt? I googled it, but no helpful results came up. Can someone help me?
Technically, you can create a server with nodejs [which is built with javascript]. Details can be found here
Its not possible to store the data as a file on the client.
But you can use localstorage, websql, indexeddb or simply cookies for it.
Note that all of these storages have different properties in terms of lifetime.
You could also create a blob using the blobapi and then create a dataurl and request the user to save it, using drag and drop + fileapi to read the data, this approach however will make it easy for users to modify the data.
Writing a file is posible with the new FileWriter and FileSystem APIs.
More mature solutions (not using files) have already been mentioned
Javascript does not support working with files, for data storage several options are available:
cookies
Local Storage
Server side storage
I've been reading tons of tutorials, I really like this technology, but I am missing something.
Following this tutorial http://www.youtube.com/watch?v=FZSjvWtUxYk you get JSON data from this url, http://backbonejs-beginner.herokuapp.com/users then you set your model, and collection.
I am not sure how to set this url on my own (for either local storage or database storage), I obviously need to set it to where I can GET the data or PUT/POST/DELETE data. I need to mention that I dont want to use PHP to send the data to the database, because this is a cordova app. Maybe setting data is beyond just using a URL, hopefully some one can make this clear, this should be easy points for most.
I am missing something easy here, because there is a reason they are not covering this topic extensively (maybe they are and I am overlooking it), but oh well ill ask anyways maybe someone can point this out :)
Here is the ajaxPrefilter it kind of confuses me, I know it obviously prefilters our url to point to the data, but I am not sure how to apply an appropiate url for local storage/server side.
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
options.url = 'http://backbonejs-beginner.herokuapp.com' + options.url;
});
Edit: Also I noticed that when I run a POST request, this url changes http://backbonejs-beginner.herokuapp.com/users and adds my data, this is from the RESTful services right, and what is so special about that url that it allows me to do that? In the meantime I am going to keep rewatching the backbone tutorial videos, to see what I am missing lol.
Also watching this http://net.tutsplus.com/tutorials/javascript-ajax/understanding-backbone-js-and-the-server/ starting from the beginning he actually understands what I mean, but jeffery uses PHP, which maybe I can use with cordova (pointing to a script or something) but I would rather use javascript to send data to mysql and local storage.
EDIT: Okay I see heroku is a cloud based service https://www.heroku.com/ so inside that url we were using a dummy type of service to store the data.. Okay so now how do I point the url to local storage?
Finally got it!
I came across this Backbone.js + Java Wine Cellar Application. It is an application with a Backbone front end and a Java backend. You have just to download it, set up the environment and see how it works.
There is also a tutorial, the author wrote it also in PHP, just check his blog.
Okay, so I am a noob, I am sure the way I asked this question may have gotten confusing but here is what I did.
I spent a good amount of time figuring out how to use https://github.com/jeromegn/Backbone.localStorage what I learned is, models and collections are well models and collections of data. I didn't think of it like that(should have been transparent from the get go, but oh well) inside the model and collection you need some data and so from the tutorial I followed the method of getting data was via http://backbonejs-beginner.herokuapp.com/users it contained jSON data which we could work with.
So in using local storage, we need to change where our jSON data is by using localStorage: new Backbone.LocalStorage("choose-some-identifier"),
So understanding the model and collection really helps in knowing what to do. Now I just need to figure out how to add localstorage data to a server, and since I am using phonegap it would be cool to add an event listener for when the user connects to the internet and on that event submit the local storage data to the server.
I attempting my first SPA.
It will be a HTML representation of the model of our database structure to give to clients to look through the model and do queries of the database model (not the database data itself).
The requirement is then for no updates and the SPA will be shipped with the release and thus will be offline. Currently it is a static HTML page.
My question is - is there a way to use breeze to query the json file I've created that describes the model? All I've seen are examples of the EntityManager being initialised with a service URL - that will return the data.
Not quite sure I understand the question. What do you mean by (no server)?. Does this mean that you want to bring all of the data down just once and then query it locally?
If the data that you want to query is actually itself metadata then if you describe the structure of the metadata (i.e. metadata of metadata) in Breeze's native metadata format, then you should be able to query the metadata itself via Breeze's EntityQuery.
Probably a little more info would be helpful.
Also, take a look at the Breeze NoDb sample for an example of "custom" metadata construction.