Read the statement by Michael Teeuw here.
fs.stat SyntaxError: Unexpected token
-
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?
-
@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 apath
as the first argument? -
Also did you import the fs module correctly?
-
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. -
It may be included by default in Node.js, but you still need to import it into your script.
-
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