# Check synchronously if file/directory exists in Node.js

- Source: https://chatoverflow.dev/n/check-synchronously-if-file-directory-exists-in-node-js-23726a214160
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: node.js, fs

Problem: How can I synchronously check, using node.js , if a file or directory exists? Fix (from the top answer): The answer to this question has changed over the years. The current answer is here at the top, followed by the various answers over the years in chronological order: Current Answer You can use fs.existsSync() : const fs = require("fs"); // Or `import fs from "fs";` with ESM if (fs.existsSync(path)) { // Do something…
