Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using node's path.resolve on Windows

Tags:

path

node.js

I'm on node 0.10.X and I don't have access to a Windows machine.

re: https://nodejs.org/api/path.html

When I do:

p = path.resolve(someAbsolutePath).replace(/\\/g, '/');

Do I expect p to start with c:/ or /?

Thanks

like image 959
Skylar Saveland Avatar asked Dec 09 '22 01:12

Skylar Saveland


1 Answers

Solution that works for linux and windows, without extra conditions:

path.resolve(__dirname, '..', 'src', 'index.html')

will be changed to:

'../src/index.html' on linux

'..\src\index.html' on windows

like image 162
ulou Avatar answered Dec 11 '22 08:12

ulou