TL;DR
Use path.join(__dirname, '..', 'test', 'karma.conf.js')
. Prevent use of slashes.
Long Answer
As a lot of answers have pointed out, using path
module is probably the best way.
However, most of the solutions here have gone back to using slashes like:
path.join(__dirname+'../test/karma.conf.js')
However, by doing this, you’re beating the purpose of using path
. One uses path
to do operations irrespective of the underlying OS (Linux, Windows etc). Just to give a bit of insight, you can do the path operations directly as string operations (like __dirname + '../test/karma.conf.js'
. You do not do this because Linux uses forward slashes ( /
), Windows uses backward slashes ( \
). This makes your application prone to errors when you port it across operating systems.
Thus, the better way would be:
path.join(__dirname, '..', 'test', 'karma.conf.js')
And of course, coming back – prevent use of slashes in your path.join
, instead spread out your params.