M
M
Mothersprogrammer2020-08-20 19:36:52
Node.js
Mothersprogrammer, 2020-08-20 19:36:52

how to change json in vue cli

I'm not strong in node.js, but I decided to try to use it, so that when changing an array with objects, it all goes into a json file, that's what I came up with:

const fs = require('fs');
  export default {
        ...
        changeJSON(){
          fs.readFile('todo.json','utf-8',(err,data) => {
            let obj = this.todos

            fs.writeFile('todo.json', JSON.stringify(obj), (err) => {
                if (err)
                    console.log(err);
            })
          })
        },
        ...

Vue cli seems to create a local server, and the question is why this method does not work? An error is displayed in the console that fs.readFile is not a function (Error in v-on handler: "TypeError: fs.readFile is not a function")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question