-1

So I have information i need to save. I am using a JavaScript object then I store the info in a JSON file.

But I want to put my project on a server and run it. but currently I am using fs to read and write data. how would i do that on a server

Xenen
  • 9
  • 4
  • So what's your web server? If you're running Tomcat, you can use Java I/O. If you're running Apache with PHP, you can use PHP fopen()/fwrite(). If you're running IIS, you can use .Net System.IO. The possibilities are endless... – FoggyDay May 12 '20 at 05:53
  • If you are asking about the the `path` you can use `__dirname`. And it will both locally and on server alike. Hope I got your question right – Zain Zafar May 12 '20 at 06:06
  • @FoggyDay I believe they're using `Node.js` as outline in the question. – Dane Brouwer May 12 '20 at 06:07
  • Does this answer your question? [Writing files in Node.js](https://stackoverflow.com/questions/2496710/writing-files-in-node-js) – Dane Brouwer May 12 '20 at 06:08

1 Answers1

0

You can have the JSON file in the server and read/write to it the same way you are doing locally, it makes no difference.

That said, I'd recommend using something like http://npmjs.com/package/json-server to make it work like an actual server API.

andrralv
  • 810
  • 7
  • 18