2021年4月3日星期六

submit button does not run checker function

I am not sure if this has anything to do with async / sync code (I think it does and I probably don't understand it well enough). So I have a few node fs functions in my code below and the point of the button is to take the user input as value to variable "folderName". folderChecker function will check if directory is there and directoryMaker will either create or reject.

I tried without any event listeners by just running "node index.js" in the repl and it creates the folders fine.. but whenever run "directoryMaker" as a function after I click my submit button it gives me a 404 error. I am not sure what I am doing wrong and need some guidance.

Thank You.

const dName = document.querySelector('#dName');  const submitButton = document.querySelector('.submit');  const fs = require('fs');    let folderName;    const folderChecker = () => {      let exists;      try{          fs.accessSync(`../../Projects/Personal/${folderName}`);          return exists = true;      } catch(err){          return exists = false;      }  }      const directoryMaker = () => {      if(folderChecker()){          console.log(`The directory of ${folderName} already exists`)      } else {          fs.mkdirSync(`../../Projects/Personal/${folderName}`);          console.log(`The directory of ${folderName} has been created`)          return;      }  }      submitButton.addEventListener('click', (e)=>{      e.preventDefault()      folderName = dName.value;      directoryMaker();    })      
https://stackoverflow.com/questions/66937670/submit-button-does-not-run-checker-function April 04, 2021 at 11:03AM

没有评论:

发表评论