How can I go to the parent directory when using __dirname?

Directory structure:

  • WebApiRole
    • Gulpfile.js
  • test
    • Karma.conf.js

Gulp code GulpFile.js

gulp.task('test', function (done) { karma.start({ configFile: _configFile: __dirname + '\\..\\test\\karma.conf.js', singleRun: true }, done); }); 

So, my problem goes to the parent directory and access to karma.conf.js . For some reason, the path will not be resolved with ..\\ to return to the parent directory of WebApiRole. can someone point me in the right direction?

+5
source share
1 answer

I had to use the path package to solve this problem.

 var path = require("path"), fs = require("fs"); gulp.task('test', function (done) { karma.start({ configFile: fs.readFile(path.join(__dirname, '../test/', 'karma.conf.js')), singleRun: true }, done); }); 
+14
source

All Articles