How to get the folder containing the current program in JavaScript

2 Answers

0 votes
const dir = __dirname;
 
console.log(dir);
 
   
   
/*
run:
       
/tmp/tqrBRaMPxM
 
*/

 



answered Jun 3, 2025 by avibootz
0 votes
const path = require('path');

const dir = path.resolve();
 
console.log(dir);

   
/*
run:
       
/tmp/3QMDsamXZC
 
*/

 



answered Jun 3, 2025 by avibootz
...