简体   繁体   中英

Polymer 2.0 - Can you write to fs?

I'm working on an MVP for a project, and I'm trying to mock up a "database" quick and dirty. I thought for now I'll just put my "database" into a .json file and work with that. I am able to use iron-ajax to get a file read in to a Polymer property to be manipulated, however, I don't know how I could write it back onto the filesystem once I manipulated it. I tried

let fs = require('fs');
fs.writeFile('./db/db.json', json, 'utf8');

However, this does not work ( apparently , require does not work on the client side). I've tried googling around and checking the answers on the linked thread, but the answers are quite vague ("use <script> tag" - okay, but how?) and I haven't been able to figure it out. How would I be able to pass a json object and write it back to the filesystem?

Simple answer is no you can't. You have to write a little backend for that but for that i usually use the localStorage there you can store JSON and read write.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM