No request database, is static server; Request the database, is the dynamic server; The database is not a front-end domain. We only need to learn about databases, but we don’t need to learn about databases, so today we will use JSON files as databases

[
    {"id":1,"name":"frank","password":"xxx"},
    {"id":2,"name":"jack","password":"zzz"}
]
Copy the code
Const usersString = fs.readfilesync ('./db/user.json').toString() const usersArray = Parse (usersString)// Convert strings into arrays //console.log(typeof usersString)// console.log(usersString) //console.log(typeof) Const user3 = {id:3,name:' Tom ',password:'yyy'} userSarray.push (user3) console.log(usersArray) // Write database // Write database const user3 = {id:3,name:' Tom ',password:' YYy '} userSarray.push (user3) const string = JSON.stringify(usersArray) fs.writeFileSync('./db/user.json',string)Copy the code

After the database is written, it will appear in JSON and write the contents of the database