Managing json files on the server with nodejs - javascript

Recently, I found that there is called 'LowDB' and it can control the json file with NodeJS.
Actually, I can use MySQL or other databases but I think the App that I developing now is small application so it needs very tiny DB like simple Json.
This Link is connected to lowDB example.
Link
https://github.com/typicode/lowdb
As you can see it controls json file and it includes CRUD(Create, Read, Update, Delete) function. But the data are save in Local storage not in server. So Even I control the json files it will only apply in Local Json file. I want to save it in server.
How can I manage json file with NodeJS? Please give me some keywords or introduce some Node Dependencies.

Related

How to fetch data as .csv file from client with node.js application

i have written a game in javascript with the p5.js library. Now i want to host the game on a server to conduct a survey on a service like amazon turk. Ideally the clients recieve a URL to the game and play it while in-game actions are tracked and stored in node.js or on the server and exported as a .csv file once they are done playing. After they finish the game the csv. file should be sent automatically to a location that i can then access. I have zero experience in server hosting or similar topics.
So a couple questions arise:
Is a hosting service like Heroku suitable for hosting the game?
Do i need to use node.js to make this happen?
Which of those two would extract the data and store it to a csv? And where is the file stored?
How do i get or access the csv. after?
Any alternative takes to solve the problem?
Thanks alot in advance!
github repository: https://github.com/luuuucaaa/schaeffers-charade
game on github pages: https://luuuucaaa.github.io/schaeffers-charade/
If I were you, I would do it like below:
Host
Since your project is basically a html & JavaScript static contents,
AWS S3's static hosting would be sufficient (Also, the current git hub pages is another option if you just want to host it).
Hosting on node.js environment is also available using webpack serving, but it requires additional works. (but if you require other npm packages to generate .csv file, you need webpack anyway to bundle js file and attach it to html)
Data Storing
Two ways are considerable,
the first is to store it on the filesystem. Generate .csv via JS script within your app, and save it where the app is hosted (if you go with s3, you can access it afterwards, but I'm not sure if it can write objects by script)
The second is to post the data to another API endpoint. (for example building an API Gateway on AWS that triggers Lambda, which stores it on S3)
It's merely an example and I don't know exactly what you want to achieve, but take it into considerations. Good luck. Cool game BTW.

How to read in sqlite information in javascript without writing your own API?

Most of my experience with database manipulation has been through node.js, and writing simple APIs for class. I'm now trying a private project, where I would write a database, and read in information from it to display on a website hosted through github. however, for what I'm doing, an API seems unnecessary, as I should be able to upload the database file onto github, and have the website read from that, rather than hosting a node.js server. So, what I'm asking is at a high level, how would I get information from a database into a form I can read onto a website, and would just creating a json locally, or storing the info some other way, be a better solution?
If the database is very large, then this really should be done server side.
If the database is small, one option is to convert the sqlLite database to JSON, and then just use fetch to grab, and just parse using Javascript.
But another option I think you might like, is use a sqLite client compiled for the browser. If your browser is relatively new and supports webAssembly you might find this interesting.
https://github.com/sql-js/sql.js
Basically sqLite compiled for the browser..
One issue with any of these is security, anybody could of course download the JSON or Sqlite database in full and have full access. Server side you can implement user authentication etc.

Save a file with nodejs to external server

So i have set up a basic nodejs server using express and everything works fine. I have a json file in my folder that i want to be able to modify, to add some data or remove some.
What is the best way to do that without the user being able to interact with the actual file? Perhaps a database that i could send my data to?
I am very new to nodejs and javascript so anything that is as simple as possible is the best.
You could create different http routes for setting and fetching data in the json file.
Say, for example:
GET /data would read the json file and respond with the contents of the file.
POST /data could post the contents of the file.
PUT /data/key could be used to modify the contents of one single key in the json.
That being said, this looks like something that you should be using a DB for. If somewhere down the line, you choose to dockerize your app, everytime you restart your server, your JSON file would be reset to the initial config.
To avoid that, a db could be used. Mongo is a good place to start considering your choice of language and nature of your data.
Hope you find this helpful :)

Store JSON data received from a website hosted on github-pages

So I am working on a webpage (hosted on github pages) where I need to convert the data entered by the user to a json object and then saving it to a file on the github repo for later use.
So far, I've converted the data to a json object, but I'm facing difficulty in storing this object to a .json file in my github repository.
Any suggestions on this would be appreciated.
Cheers.
As MAttds17 said you will need a server side.
If your code will be simple, you can use a Backend as a service like Firebase or Backand.
If you think you will have heavy logic in your server side, you can host a real application in Heroku or another alternative.

Read json file in nested folders

I have director structure like this, only $(Root Directory)'s name is known at run time.
other folders and files are generated dynamically.(All files are .json)
my requirement is I need to count no of files and read content of all files using jquery and ajax.
I know if we have some static path like abc/xyz/somefile.json then we can read someFile.json but in my case I need to traverse nested folders.
help
You will not be able to do it without server-side support, either from the web server itself or another server-side process.
If directory listing is enabled on your web server, you can make an ajax request directly to the directory you want and scrape the returned document's content.
Another way would be to setup a web service which allows to query a directory's content. That service would be responsible for querying the file system and return the information to the client in a data-interchange format like JSON.

Categories