Node: Use and return forward slash in Path sep even on Windows

Created on 5 Jun 2015  路  6Comments  路  Source: nodejs/node

Windows and DOS all the time supported both directory delimiters. Number of places in Windows where forward slashes are not allowed is very small and should be considered buggy.
Current situation makes writing platform independent code extremely complex, in many cases integration tests of projects created by Unix guys just don't work on Windows (and vice versa).

Finally this separation brings more harm then good.
It would also fix https://github.com/nodejs/io.js/issues/616 - Path.relative would always return correct url separators.

I am not that naive, that I would expect this will be fixed, because it would probably break too many (probably mainly Windows) projects. But I would like to know view of node community about this problem.

path windows

Most helpful comment

You can use the path.posix namespace on every platform to use / instead of the platform-dependent slash.

All 6 comments

I don't think it makes sense to change this. Using \ on Windows is more correct IMO. And, there is undoubtedly a ton of code in the ecosystem that relies on the existing behavior.

You can use the path.posix namespace on every platform to use / instead of the platform-dependent slash.

@mscdex It is not bad idea. In some cases it is really used everywhere in project - every npm module, so in that case would you advice to monkey patch require or there is better way?

@Bobris Well, probably adding url.relative() would be better and having module authors use that instead of path.relative(). If url.relative() doesn't get added for some reason, then authors should probably use path.posix.relative(). However that obviously won't work for node v0.10 if people care about that.

What would this make better that justifies potential ecosystem breakage?

Closing, The ecosystem is already quite heavily built on this. :s

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielstaleiny picture danielstaleiny  路  3Comments

jmichae3 picture jmichae3  路  3Comments

Brekmister picture Brekmister  路  3Comments

willnwhite picture willnwhite  路  3Comments

cong88 picture cong88  路  3Comments