ReferenceError: __dirname is not defined
dcjayasuriya2020 opened this issue · comments
dcjayasuriya2020 commented
code in the datafile is lib.baseDir = path.join(__dirname, '/../.data/');
in git bash it indicates when run for test err,
$ node index.js
file:///E:/Learn/lib/data.js:15
lib.baseDir = path.join(__dirname, '/../.data/');
^
ReferenceError: __dirname is not defined
How to get clear on this?
xuych commented
const __dirname = path.resolve();
Luis Enrique Mora commented
import path from 'path';
import { fileURLToPath } from 'url';
// data path
const __filename = fileURLToPath( import.meta.url );
const __dirname = path.dirname( __filename );
//* Base directory of the data folder
const templateDir = path.join( __dirname, '/../.data/' );