MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    fs.stat SyntaxError: Unexpected token

    Troubleshooting
    3
    6
    2322
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      pepebc last edited by pepebc

      Hello everyone,
      I try to apply fs.stat to find if a file exists but I constantly get this error:

      fs.stat((err) => {
        ^
      SyntaxError: Unexpected token .
      

      Can someone help me how to fix it?

      N 1 Reply Last reply Reply Quote 0
      • N
        ninjabreadman @pepebc last edited by

        @pepebc It may depend on what precedes that snippet (if anything). Try copy/pasting the whole file into JSHint, it may give you a better idea. Also, doesn’t fs.stat() take a path as the first argument?

        Problem with config or JavaScript? Copy/paste it into JSHint.
        Check out the detailed walkthroughs on install, config, modules, etc.

        1 Reply Last reply Reply Quote 1
        • strawberry 3.141
          strawberry 3.141 Project Sponsor Module Developer last edited by

          Also did you import the fs module correctly?

          Please create a github issue if you need help, so I can keep track

          1 Reply Last reply Reply Quote 0
          • P
            pepebc last edited by

            fs is included by default in nmp.
            I do tests because I need to verify that a text file exists in the module directory when an attempt was made to create.
            I am not an expert in programming and I am trying with the functions that I find online. Always it gives me that error, although in the forums seems to work. In this environment, it gives me problems.

            N 1 Reply Last reply Reply Quote 0
            • N
              ninjabreadman @pepebc last edited by

              It may be included by default in Node.js, but you still need to import it into your script.

              Problem with config or JavaScript? Copy/paste it into JSHint.
              Check out the detailed walkthroughs on install, config, modules, etc.

              1 Reply Last reply Reply Quote 0
              • P
                pepebc last edited by pepebc

                Yes, I had imported it with const fs = require ('fs');
                but I was not creating the function well in the right place. Thank you.
                It’s crazy what I want, I know. I want to connect Kalliope (modular always-on voice controlled personal assistant) - https://kalliope-project.github.io with MagicMirror. I find it a very powerful and flexible tool. The program I already manage it well separately and I have created “neurons” and “events” … etc, but it would be wonderful to interact with MagicMirror modules.
                Lights, sensors, temperature, webcam, notifications, reading email, music … etc, that I already have it integrated in Kalliope

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy