Tuesday, 16 June 2020

json.parse ins't passing into another function

Hello,I'm using fs to read a json file to test some authentication JavaScript. But, I get the error that users.find is not a function. Here's my code. I apologize if this error is a simple fix; I am new to node.const fs = require('fs');const users = fs.readFileSync('./users.json', 'utf-8', (data) => {JSON.parse(data).users; })module.exports = {authenticate,};async function authenticate({ username, password }) {const user = users.find(u => u.username === username && u.password === password  );  if (user) {const { password, ...userWithoutPassword } = user;return userWithoutPassword;  }}Any suggestions? Thanks!!!!

Submitted June 16, 2020 at 09:18PM by LGm17

No comments:

Post a Comment