Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

node fs exists

const { promises: Fs } = require('fs')

async function exists (path) {  
  try {
    await Fs.access(path)
    return true
  } catch {
    return false
  }
}

// Example:
const Path = require('path')  
const path = Path.join(__dirname, "existing-file.txt")

await exists(path)  
// true
Source by futurestud.io #
 
PREVIOUS NEXT
Tagged: #node #fs #exists
ADD COMMENT
Topic
Name
1+6 =