Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

javascript - How to go back 1 folder level with __dirname?

I am using gulp-karma and facing a simple problem but cannot seems to find what i am doing wrong .

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

Here is the code i am using and i cannot seems to go 1 level back in the folder directory . When i do the above it just append the .. to the folder direcotry without going 1 level back (which is the usual use of ..). Following is the folder structure .

parent|
      test|karma.conf.js
      webapirole|gulpfile.js

and my folder is inside the webapirole folder . i want to go back 1 folder back and go inisde the test folder which contains the karma.conf.js file. can anyone make me understand what i am doing wrong here ?

error i am getting

[18:06:32] Starting 'tdd'...
ERROR [config]: File C:UsersDocumentsWebApiRole..estkarma.conf.js does not exist
question from:https://stackoverflow.com/questions/30845416/how-to-go-back-1-folder-level-with-dirname

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am using (path) NPM for the above usage......

simply require path npm in js file.Then use

let reqPath = path.join(__dirname, '../../../');//It goes three folders or directories back from given __dirname.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...