Not sure if I have ever figured out a good workaround for this.
I am in a directory, I want to use process.cwd() to find the currently working directory but want to move up on directory, something like so:
var serverPath = path.resolve(process.cwd() + '../bin/www');
however, this obviously won't work, and will give me an error along these lines:
Error: Cannot find module '/Users/amills001c/WebstormProjects/ORESoftware/suman../bin/www'
so what is the best way to use process.cwd() and move up a directory?
You just need a /
before the ..
:
var serverPath = path.resolve(process.cwd() + '/../bin/www');
You're missing a \
.
You should consider calling path.join(process.cwd(), '../bin/www');
before you pass it to path.resolve
. This will help get the slashes correct. Concatenation of file paths is generally considered risky business.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With