How do i go to parent directory when using __dirname?

蹲街弑〆低调 提交于 2019-12-07 05:30:10

问题


Directory structure :

  • WebApiRole
    • GulpFile.js
  • test
    • Karma.conf.js

Gulp code from GulpFile.js

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

So my problem going to the parent directory and access the karma.conf.js . For some reason the path is not get resolved with ..\\ to go back to the parent directory of WebApiRole . can someone point me in the right direction ?


回答1:


I had to use path package to resolve this issue .

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);
});


来源:https://stackoverflow.com/questions/30858775/how-do-i-go-to-parent-directory-when-using-dirname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!