Skip to content
Advertisement

Node.JS readFileSync() function

index.js

JavaScript

server.js

JavaScript

router.js

JavaScript

index.html

JavaScript

I’m trying to store the file path in a variable and then feed it ti readFileSync() function, but this gives me fllowing error in the console.

JavaScript

but if I enter the path “D:/nodejs/file_upload/view/index.html” in the function directly then it shows me the page in the browser.

I stored the index.html file in the view folder

Advertisement

Answer

EISDIR error occurs when you try to open a file, but the path given is a directory. See related question and answer: Using Node.js I get, “Error: EISDIR, read”.

To debug this I would log to console the variable directpath and I would assume that it is pointing to a directory, not a file. Correctly setting this variable to the intended path should solve your problem.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement