MSNCodeSNIPPETS← msncode.dev
snippets/nodejs

Get Current Directory Path

Get the directory of the currently running script

nodejsjavascriptpathdirectory
JAVASCRIPT
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));

More nodejs snippets

Check if Directory Exists

Check if a path exists and is a directory

Fetch with Timeout

Add a timeout to fetch requests using AbortController

Safe JSON Parse

Parse JSON without try-catch crashing your app

Read Environment Variable

Access environment variables in Node.js